Html 如何将两个 span 元素一个向左对齐,另一个向右对齐?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9303976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I align two span elements one to the left, the other one to the right?
提问by antonpug
I have two <span>
elements:
我有两个<span>
要素:
<span style="margin-right:auto;">?2012 XYZ Corp. All Rights Reserved.</span>
<span style="margin-left:auto;">Built with <a href="http://www.wordpress.org/">Wordpress</a> and hosted by <a href="http://www.mediatemple.net/">(mt)</a> in California.</span>
I want the first <span>
to be on the left of the page and the second <span>
to be on the right side, regardless of page width (so I can't use fixed positioning).
我希望第一个<span>
在页面的左侧,第二个<span>
在右侧,无论页面宽度如何(所以我不能使用固定定位)。
What CSS can I use to do this?
我可以使用什么 CSS 来做到这一点?
回答by paulcol.
The css variable float
is used to position your elements.
css 变量float
用于定位元素。
The options are:
选项是:
float:left;
float:right;
float:none;
<span style="float:left;">?2012 XYZ Corp. All Rights Reserved.</span>
<span style="float:right;">Built with <a
Here is working example:
这是工作示例:
<span style="float:left; color: red;">?2012 XYZ Corp. All Rights Reserved.</span>
<span style="float:right; color: blue;">Built for example</span>