【发布时间】:2014-12-27 17:35:52
【问题描述】:
我发现了一些这样的问题,但我找不到答案:是否可以在每个 col-xs-1 引导单元中垂直居中图像,但不要用 float:none 杀死流体网格系统? jsfiddle project
HTML:
<div class="container">
<div class="row row-table">
<div class="col-xs-1 col-xs-1-table-cell">
</div>
<div class="col-xs-1 col-xs-1-table-cell">
<img src="http://placehold.it/50x50/" width="50" height="50"/>
</div>
<div class="col-xs-1 col-xs-1-table-cell">
<img src="http://placehold.it/100x100/" width="100" height="100"/>
</div>
</div>
css:
div.row {
border: solid 1px blue;
}
.row-table {
display: table;
width: 100%;
}
div.col-xs-1 {
width:150px !important;
height:160px !important;
border: solid 1px yellow;
}
.col-xs-1-table-cell {
display: table-cell;
text-align: center;
vertical-align: middle;
// float:none;
}
请取消注释 float:none;在 css 部分中,图像将居中,但单元格的流畅布局将被破坏(您可以更改浏览器窗口大小以尝试)
【问题讨论】:
-
您有两个答案,请确保检查它们并标记您使用的答案是否正确
标签: html css twitter-bootstrap-3 vertical-alignment