CSS在带有span的段落中左右浮动?

发布于 2024-09-26 06:11:11 字数 433 浏览 0 评论 0原文

到目前为止,当我有一行包含

前一个 --- 页面宽度 --- 接下来的

示例时,我使用了一个带有 2 个子元素的容器 div,样式为 float:left & float:right

我认为它可以从一个带有 span 的段落行完成,可能是这样的:

<p><span class="s-left">previous</span><span class="s-right">next</span></p>

我尝试了 CSS with:

span.s-left { text-align: left; }
span.s-right { text-align: right; }

但这并没有做到。

Until now, when I had one line with example

previous --- page width --- next

I used a container div with 2 children, styled float:left & float:right

I am think it could be done from one paragraph line with span's maybe something like:

<p><span class="s-left">previous</span><span class="s-right">next</span></p>

I tried CSS with:

span.s-left { text-align: left; }
span.s-right { text-align: right; }

but that doesn't do it..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-10-03 06:11:11

这是因为 span 默认情况下显示为 inline,因此它没有定义要对齐的文本的宽度in(这是一个非常宽松的描述,但现在就可以了)。

如果您想要左右对齐文本,这并不难,只需:

p {
text-align: right;
}
span.s-left {
float: left;
}

可以在 JS Bin

That's because span is by default displayed inline, so it has no defined width for the text to be aligned in (that's a very loose description, but it'll do for now).

If you want to have right and left aligned text it's not much harder, just:

p {
text-align: right;
}
span.s-left {
float: left;
}

A demonstration may be found at JS Bin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文