I'm using Twitter Bootstrap 3, and I have problems when I want to align vertically two div
, for example — JSFiddle link:
<!-- 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>
The grid system in Bootstrap uses float: left
, not display:inline-block
, so the property vertical-align
doesn't work. I tried using margin-top
to fix it, but I think this is not a good solution for the responsive design.
Try this,
Flex behaviors are natively supported since Bootstrap 4. Add
d-flex align-items-center
in therow
div. You no longer need to modify your css.Simple example : http://jsfiddle.net/vgks6L74/
With your example : http://jsfiddle.net/7zwtL702/
Source : https://getbootstrap.com/docs/4.0/utilities/flex/
With Bootstrap 4 (which is in alpha currently) you can use the
.align-items-center
class. So you can keep the responsive character of Bootstrap. Workes straight away fine for me. See Bootstrap 4 Documentation.No need for table and table-cells. It can be achieved easily using transform. Example: http://codepen.io/arvind/pen/QNbwyM
Code:
Try this in the CSS of the div: