float
包含段落的元素,
float: left
float: right
最后一行。浮动的容器将与整个段落一样宽,因此右浮动最后一行将使其右边缘与前面文本的右边缘对齐。
例子:
<div style="float: left">
<span style="float: left">
Once upon a midnight dreary, while I pondered, weak and weary,<br/>
Over many a quaint and curious volume of forgotten lore,<br/>
While I nodded, nearly napping, suddenly there came a tapping,<br/>
As of some one gently rapping, rapping at my chamber door.<br/>
"'T is some visiter," I muttered, "tapping at my chamber doorâ<br/>
</span>
<span style="float: right; clear: left">Only this, and nothing more."</span>
</div>
它的
父容器,可以将最上面的设置为
text-align: center
display: inline-block
对于文本容器。如果你用这种方法,我认为你不需要浮动它:
<div style="text-align: center">
<div style="display: inline-block; text-align: left">
<span style="float: left">
Once upon a midnight dreary, while I pondered, weak and weary,<br/>
Over many a quaint and curious volume of forgotten lore,<br/>
While I nodded, nearly napping, suddenly there came a tapping,<br/>
As of some one gently rapping, rapping at my chamber door.<br/>
"'T is some visiter," I muttered, "tapping at my chamber doorâ<br/>
</span>
<span style="float: right; clear: both">Only this, and nothing more."</span>
</div>
</div>