编辑:发现答案评论中! 感谢! ;)
我需要一些垂直中间对齐的文字,具有最大高度限制(比如说60px)
问题在于我无法将高度设置为table-cell
。
另一方面,如果我没有table-cell
我没有中间对齐。
如何解决这个问题?
Bellow是我的代码(CodePen HERE)
.row { width: 900px; }
.row > div {display: table; }
.row > div > div {display: table-cell; vertical-align: middle; font-size: 1em;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-4 text-center" style="background:green">
<img src="http://placehold.it/60?text=60">
<div style="background: yellow"> 1Middle-vertical text green-yel </div>
</div>
<div class="col-xs-4 text-center" style="background:green">
<img src="http://placehold.it/60?text=60">
<div style="background: yellow"> 1Middle-vertical text green-yel 2Middle-vertical text green-yel </div>
</div>
<div class="col-xs-4 text-center" style="background:red">
<img src="http://placehold.it/60?text=!60">
<div style="background: yellow"> 1Middle-vertical text red-yel 2Middle-vertical text red-yel 3Middle-vertical text red-yel 4Middle-vertical text red-yel </div>
</div>
</div>