这应该使所有单元格 65px 高,并使单元格的文本显示在中间。当文本太多时,文本会在下面消失。
我相信这是你想要的?
CSS:
.row {
border: solid 1px blue;
display: block;
height: 65px; /* arbitrary value */
overflow: hidden;
line-height: 65px; /* same as height */
}
.cell {
border: solid 1px #CCCCCC;
display: inline-block;
vertical-align: middle;
height: 100%;
}
.cellContents {
display: inline-block;
max-height: 100%;/*would 100%; work?*/
width: 100px; /* arbitrary value */
overflow: hidden;
border: solid 1px red; /* just to see that it's centered */
line-height: 100%; /* so it does not inherit the huge line-height, and we get more than one line of text per cell */
}
HTML:
<div class="table">
<div class="row">
<span class="cell"><span class="cellContents">cell 1 1</span></span>
<span class="cell"><span class="cellContents">cell 1 2</span></span>
<span class="cell"><span class="cellContents">cell 1 3</span></span>
</div>
<div class="row">
<span class="cell"><span class="cellContents">cell 2 1</span></span>
<span class="cell"><span class="cellContents">This should make all the cells 65px high, and make the cells' text show up in the middle. When it's too much text, the text disappears bellow.</span></span>
<span class="cell"><span class="cellContents">cell 2 3</span></span>
<span class="cell"><span class="cellContents">cell 2 4</span></span>
</div>
</div>
你可以在JSFiddle上试试。