我试图在这里的例子中垂直对齐第二个div。一个div中的文本可以是变化的,可以在任何地方从1-50字符.第二个div可以从4-7个字符变化,但如果一个div中的文本更大,则需要垂直对齐。
html
<div class="wrap">
<div class="two">result</div>
<div class="one">This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string</div>
</div>css
div.wrap
{
width: 200px;
}
div.one {
border: 1px solid #AAAAAA;
white-space: normal;
word-wrap: break-word;
}
div.two {
background-color: #7bbf7b;
float: right;
}http://jsfiddle.net/mg5wpmur/
发布于 2014-08-20 17:39:44
使用显示表。
举个例子!
HTML
<div class="wrap">
<div class="one">This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string This is a long string</div>
<div class="two">result</div>
</div>CSS
div.wrap
{
width: 200px;
display: table;
}
div.one {
border: 1px solid #AAAAAA;
white-space: normal;
word-wrap: break-word;
display: table-cell;
}
div.two {
background-color: #7bbf7b;
display: table-cell;
vertical-align: middle;
}https://stackoverflow.com/questions/25410970
复制相似问题