我正在使用Twitter Bootstrap 3,并且在我想垂直对齐两个时遇到问题div
,例如-JSFiddle链接:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-5">
<div style="height:5em;border:1px solid #000">Big</div>
</div>
<div class="col-xs-5">
<div style="height:3em;border:1px solid #F00">Small</div>
</div>
</div>
Bootstrap中的网格系统使用float: left
,而不是display:inline-block
,因此该属性vertical-align
不起作用。我尝试使用margin-top
修复它,但是我认为这对于响应式设计不是一个好的解决方案。
I ran into the same situation where I wanted to align a few div elements vertically in a row and found that Bootstrap classes col-xx-xx applies style to the div as float: left.
I had to apply the style on the div elements like style="Float:none" and all my div elements started vertically aligned. Here is the working example:
JsFiddle Link
Just in case someone wants to read more about the float property:
W3Schools - Float