左对齐并将文本居中在同一行
我有一个 div
,其中我需要在同一行上放置居中文本和左对齐文本。这个jsfiddle演示了我到目前为止所拥有的: http://jsfiddle.net/nDqvT/
问题是左对齐的文本会将居中的文本推离中心。有什么办法可以避免这种情况吗?
I have a div
in which I need to have both centered text and left-aligned text on the same line. This jsfiddle demonstrates what I have so far: http://jsfiddle.net/nDqvT/
The problem is that the left-aligned text pushes the centered text off-center. Is there any way to avoid this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果可以为左侧文本指定宽度,则可以为居中文本指定偏移边距。
http://jsfiddle.net/nDqvT/1/
If you can assign a width to the left text, you can then assign an offsetting margin to the centered text.
http://jsfiddle.net/nDqvT/1/
这是正确的吗?
http://jsfiddle.net/nDqvT/36/
Is this correct ?
http://jsfiddle.net/nDqvT/36/
干得好。
http://jsfiddle.net/nDqvT/57/
换行符
代替
用于确保包装器div
具有高度。如果没有它,包装器在内容流中看起来是空的。您可以使用
,或者只为包装器指定一个高度。编辑:
整个解决方案假设文本将按照OP全部放在一行上:“我需要将居中文本和左对齐文本放在同一行< /strong>."
任何超过一行的内容都需要到达
div
的末尾才能换行。要在窗口边缘之前到达div
的末尾,div
必须具有指定的宽度。OP 不希望
div
具有指定的宽度,也不希望文本彼此重叠。因此,OP的各种约束似乎是相互冲突的,这排除了理想的解决方案。Here you go.
http://jsfiddle.net/nDqvT/57/
The line break
or just assign a height to the wrapper.
<br />
is used to ensure that the wrapperdiv
has height. Without it, the wrapper looks empty within the content flow. Instead of<br />
, you could useEDIT:
This entire solution assumes the text will all fit on one line as per the OP: "I need to have both centered text and left-aligned text on the same line."
Anything longer than one line and it needs to hit the end of the
div
in order for it to wrap. To reach the end of adiv
before the edge of the window, thediv
must have a specified width.The OP does not want the
div
's to have a specified width nor does he want the texts to overlap each other. Therefore, it seems like the various constraints of the OP are in conflict with each other which precludes an ideal solution.