[英]how to put these two on the same line? (one centered, one right aligned)
I am trying to align two different sets of text to be on the same line. 我正在尝试将两组不同的文本对齐在同一行上。
<h2 style="text-align:center">Only $4 for first-class shipping on all orders!</h2><span style="text-align:right">test</span>
I'm trying to have these on the same line. 我正在尝试将它们放在同一行上。 i thought the span tag did it, but it doesnt. 我以为span标签做到了,但是没有。 when i put it in a div, it goes down a line, i need it on the same line. 当我将它放在div中时,它沿着一条线下降,我需要在同一条线上。
You need to put display:inline on that H2 tag since it's a block element as default. 您需要在该H2标签上放置display:inline,因为默认情况下它是一个块元素。
http://jsfiddle.net/MWDxC/2/ http://jsfiddle.net/MWDxC/2/
Or you could just move the entire span tag inside the H2 and that would work as well. 或者,您可以将整个span标签移动到H2内,这样也可以正常工作。
You need a wrapping element, change the display and set a float. 您需要一个包装元素,更改显示并设置一个浮点数。 Then it will work. 然后它将起作用。
<div style="text-align:center;">
<h2 style="display:inline;" >Only $4 for first-class shipping on all orders!</h2>
<span style="float:right; display:block;">test</span>
</div>
If you want to keep the <h2>
centered and the <span>
on the right - http://jsfiddle.net/MWDxC/3/ 如果要保持<h2>
居中且<span>
在右侧-http://jsfiddle.net/MWDxC/3/
<header>
<h2>Only $4 for first-class shipping on all orders!</h2>
<span>test</span>
</header>
header {
position: relative;
}
h2{
text-align: center;
}
span {
position: absolute;
right: 0;
top: 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.