[英]two spans, one left aligned, one right aligned, both bottom aligned
I'm trying to put two spans in a div, one on each side, and both aligned to the bottom of the div, without using absolute positioning (since that ignores padding, etc and I always feel bad after resorting to it). 我试图在div中放置两个跨度,每侧一个跨度,并且都与div的底部对齐,而不使用绝对定位(因为它会忽略填充等),而诉诸它后我总是感到难过)。 The text in the right span is taller than in the left span.
右跨度中的文本比左跨度中的文本高。 If I use vertical-align to position them, it doesn't take affect if they are both floated, however without them both being floated, they will not be horiziontally aligned properly.
如果我使用vertical-align来定位它们,则它们都没有漂浮不会发生影响,但是如果没有它们都漂浮,它们就不会正确地水平对齐。 I don't have any guarantees on which of the two spans will have more text in it.
我无法保证这两个跨度中的哪个会包含更多文本。
http://jsfiddle.net/gsvfn07f/ http://jsfiddle.net/gsvfn07f/
<div class="outer">
<div class="inner">
<span class="left">left</span>
<span class="right">right</span>
<div class="clearfix"></div>
</div>
</div>
.outer {
width: 40%;
height: 200px;
border: 1px solid red;
}
.inner {
border: 1px solid green;
padding: 5px;
}
.left {
float: left;
display: inline-block;
vertical-align: baseline;
}
.right {
float: right;
font-size: 2em;
}
.clearfix {
clear: both;
}
You can use line-height
to get margin from top for your text. 您可以使用
line-height
来获取文本的顶部空白。
This code seems to do what you want: 这段代码似乎可以满足您的要求:
.outer { width: 40%; height: 200px; border: 1px solid red; } .inner { height: 35px; width: 100%; border: 1px solid green; } .left { line-height: 48px; float: left; width: 50%; } .right { display: block; float: right; width: 50%; text-align: right; font-size: 2em; }
<div class="outer"> <div class="inner"> <span class="left">left</span> <span class="right">right</span> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.