equalheight
by justicechan
HTML
<script src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<div class="row equal-height-columns">
<div class="col">
<div class="bg equal-height-column">
1 of 2ddddfdffddffdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd
</div>
</div>
<div class="col">
<div class="bg equal-height-column">
2 of 2
</div>
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col">
2 of 3
</div>
<div class="col">
3 of 3
</div>
</div>
</div>
CSS
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.bg{
background:#00ffff;
}
JavaScript
function handleEqualHeightColumns() {
var EqualHeightColumns = function () {
jQuery(".equal-height-columns").each(function() {
heights = [];
jQuery(".equal-height-column", this).each(function() {
jQuery(this).removeAttr("style");
heights.push(jQuery(this).height()); // write column's heights to the array
});
jQuery(".equal-height-column", this).height(Math.max.apply(Math, heights)); //find and set max
});
}
EqualHeightColumns();
jQuery(window).resize(function() {
EqualHeightColumns();
});
}
// Equal Height Image-Columns
function handleEqualHeightColumns__Images() {
var EqualHeightColumns__Images = function () {
jQuery('.equal-height-columns-v2').each(function() {
var heights = [];
jQuery('.equal-height-column-v2', this).each(function() {
jQuery(this).removeAttr('style');
heights.push(jQuery(this).height()); // Write column's heights to the array
});
jQuery('.equal-height-column-v2', this).height(Math.max.apply(Math, heights)); // Find and set max
});
}
jQuery('.equal-height-columns-v2').ready(function() {
EqualHeightColumns__Images();
});
}
handleEqualHeightColumns();
handleEqualHeightColumns__Images();