我很惊讶这对我来说太难了。我需要一行,其中一些文本居中,其余的右对齐:
Centered Text Right Text
我怀疑这很重要,但“中心文本”需要是<div>
或<span>
,因为我需要使用jQuery操作其内容。 “正确文字”必须是<div>
,因此我可以将样式应用于其包含的链接。
我尝试过float: left
件事,但我无法让它发挥作用。任何帮助将不胜感激。
答案 0 :(得分:7)
<div style="float: right">Right Text</div>
<div style="text-align: center">Centered Text</div>
关键是将浮动元素放在第一位。
答案 1 :(得分:4)
<html>
<body>
<div style="background-color: #EEEEEE;">
<div style="float: right;">Right Text</div>
<div style="width: 100px; margin: 0 auto;">
Centered Text
</div>
</div>
</body>
</html>
答案 2 :(得分:3)
您需要一个div
容器text-align: center
,其中div
float:right
:
<div style='text-align: center'>
<div style='float:right'>Right Text</div>
Centered text
</div>
如果需要,您可以将Centered text
包裹在<span>
中。
答案 3 :(得分:1)
<div style="float: left; width: 65%; text-align: center">
centered
</div>
<div style="float: left; width: 35%; text-align: justify">
justified
</div>
希望这有帮助