我正在将 label
,input
和 div
元素行内显示,期望它们垂直对齐,并且最初是可以的。
但是,当我尝试使用省略号让 div
内容溢出时,它们不再垂直对齐了。
注意: 这在 Chrome 46.02490.86 中被观察到。
p {color:red;}
input,
label,
div {
width: 50px;
display: inline-block;
margin-left: 5px;
}
label {
text-align: right;
}
.longdesc {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<label>Name:</label>
<input type='text' value='James'>
<label>Desc:</label>
<div>Short</div>
<hr />
<label>Name:</label>
<input type='text' value='James'>
<label>Desc:</label>
<div class='longdesc'>Longer Description</div>
<p>
In the second example "Long" is higher up
</p>
inline-block
是为了将元素从左到右显示。block
是为了将元素垂直地排列在一起(换句话说,堆叠在彼此上方)。我明白了,您想要内容对齐,好的。 - zer00ne