CSS在段落中向左和向右浮动? [英] CSS float left and right in paragraph with span?

查看:224
本文介绍了CSS在段落中向左和向右浮动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到现在为止,当我有一行例子

Until now, when I had one line with example

previous --- page width --- next

previous --- page width --- next

我使用了一个容器div有2个孩子,样式为float:left& float:right

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

我认为它可以从一个段落行,span可能是这样:

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>

我尝试使用CSS:

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

但是不行。

推荐答案

这是因为 span 默认显示为 inline 它没有在中对文本进行对齐的宽度(这是一个非常宽松的描述,但现在它会做的)。

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;
}

演示可在 JS Bin

这篇关于CSS在段落中向左和向右浮动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆