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.
Best Answer
You still can use a custom class when you need it:
Bootply
Using
inline-block
adds extra space between blocks if you let a real space in your code (like...</div> </div>...
). This extra space breaks our grid if column sizes add up to 12:Here, we've got extra spaces between
<div class="[...] col-lg-2">
and<div class="[...] col-lg-10">
(a carriage return and 2 tabs/8 spaces). And so...Let's kick this extra space!!
Notice the seemingly useless comments
<!-- ... -->
? They are important -- without them, the whitespace between the<div>
elements will take up space in the layout, breaking the grid system.Note: the Bootply has been updated