简体   繁体   English

两个跨度,一个左对齐,一个右对齐,两个都底部对齐

[英]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.

相关问题 两个导航栏,上一个右对齐,下一个左对齐 - Two Navigation Bars, top one aligned right, bottom one aligned left 如何在同一行上有两个DIV,一个不带HTML表格,一个左对齐,一个右对齐? - How can I have two DIV s on the same line , one aligned to the left and one aligned to the right without an HTML table? 两个相邻的跨度:一个是垂直中心对齐,另一个不是。 为什么? - Two adjacent spans: One is vertically center aligned, the other is not. Why? 材质用户界面。 网格内的 2 个项目; 一个左对齐,一个右对齐。 在同一行 - Material UI. 2 items inside a grid; one left-aligned, one right-aligned. In the same line 如何使2个图标一左一右对齐? - How to make 2 icons to be aligned one to the left and one to the right? 如何使两个对象水平对齐(一个在另一个的右侧)并居中放置一个? - How can I have two objects aligned horizontally (one to the right of the other) and center the left one? 如何在表格单元格(td)中定位元素,使得一个元素左对齐而另一个元素对齐? - How can I position elements within a table cell (td) such that one element is left aligned and the other right aligned? 连续两个元素,一个左对齐,一个居中,如何? - Two elements in a row, one left aligned and one centered, how? 如何将这两个放在同一行? (一个居中,一个右对齐) - how to put these two on the same line? (one centered, one right aligned) 水平线上的两个div - 左右对齐 - Two divs on horizontal line – left and right aligned
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM