CSS 多行标签对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18778259/
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
CSS multi line Labels align
提问by William WEI
How could I align 2 labels with bottom alignments. if one label has multiple lines, the label next to it will appear from the top. could I align it to the bottom?
我如何将 2 个标签与底部对齐对齐。如果一个标签有多行,它旁边的标签将从顶部出现。我可以将它对齐到底部吗?
<div class="field">
<div class="label">labl 1:</div>
<div class="value">Some text</div>
<br />
<br />
</div>
<div class="field">
<div class="label">this is a really really long label:</div>
<div class="value">right after":" from previous label</div>
<br />
</div>
.label {
background: purple;
float: left;
width: 100px;
display: inline;
vertical-align: 500px;
}
.value {
background: red;
width: 300px;
float: right;
}
many thanks :)
非常感谢 :)
回答by koala_dev
Here are some options for you:
这里有一些选项供您选择:
Use
display:inline-block
:.label { background: purple; width: 100px; display: inline-block; } .value { background: red; width: 300px; display: inline-block; vertical-align: bottom; }
Use
display:table
andtable-cell
.field { display: table; } .label,.value{ display: table-cell; } .label { background: purple; min-width: 100px; } .value { background: red; width: 100%; vertical-align: bottom; }
Use
position:absolute
.field { position: relative; } .label { background: purple; width: 100px; } .value { background: red; width: 300px; position: absolute; right: 0; bottom: 0; }
使用
display:inline-block
:.label { background: purple; width: 100px; display: inline-block; } .value { background: red; width: 300px; display: inline-block; vertical-align: bottom; }
使用
display:table
和table-cell
.field { display: table; } .label,.value{ display: table-cell; } .label { background: purple; min-width: 100px; } .value { background: red; width: 100%; vertical-align: bottom; }
用
position:absolute
.field { position: relative; } .label { background: purple; width: 100px; } .value { background: red; width: 300px; position: absolute; right: 0; bottom: 0; }
Note:first two options won't work in IE < 8 (without some hacks)
注意:前两个选项在 IE < 8 中不起作用(没有一些技巧)
回答by George Dodge
Use this example in this example css multi line label is assign
在这个例子中使用这个例子css多行标签被分配
label {
display: block;
margin-left: 20px;
}
input {
float: left;
margin-left: -20px;
margin-right: 7px;
}
回答by Sasidharan
CSS
CSS
.label {
background: purple;
float: left;
width: 100px;
display: inline;
vertical-align: 500px;
}
.value {
background: red;
width: 300px;
float: right;
}
#bor
{
line-height:40px;
}
HTML
HTML
<fieldset>
<div class="field">
<div class="label">labl 1:</div>
<div class="value">Some text</div>
<br />
<br />
</div>
<div class="field">
<div class="label">this is a really really long label:</div>
<div id="bor" class="value">right after":" from previous label</div>
<br />
</div>
</fieldset>