How do I bottom-align grid elements in bootstrap fluid layout
Please note: for Bootstrap 4+ users, please consider Christophe's solution (Bootstrap 4 introduced flexbox, which provides for a more elegant CSS-only solution). The following will work for earlier versions of Bootstrap...
See http://jsfiddle.net/jhfrench/bAHfj/ for a working solution.
//for each element that is classed as 'pull-down', set its margin-top to the difference between its own height and the height of its parent
$('.pull-down').each(function() {
var $this = $(this);
$this.css('margin-top', $this.parent().height() - $this.height())
});
On the plus side:
- in the spirit of Bootstrap's existing helper classes, I named the class
pull-down
. - only the element that is getting "pulled down" needs to be classed, so...
- ...it's reusable for different element types (div, span, section, p, etc)
- it's fairly-well supported (all the major browsers support margin-top)
Now the bad news:
- it requires jQuery
- it's not, as-written, responsive (sorry)
This is an updated solution for Bootstrap 3 (should work for older versions though) that uses CSS/LESS only:
http://jsfiddle.net/silb3r/0srp42pb/11/
You set the font-size to 0 on the row (otherwise you'll end up with a pesky space between columns), then remove the column floats, set display to inline-block
, re-set their font-size, and then vertical-align
can be set to anything you need.
No jQuery required.
You can use flex:
@media (min-width: 768px) {
.row-fluid {
display: flex;
align-items: flex-end;
}
}