Skip to content

Instantly share code, notes, and snippets.

@jmaddington
Created March 10, 2014 03:53
Show Gist options
  • Save jmaddington/9459207 to your computer and use it in GitHub Desktop.
Save jmaddington/9459207 to your computer and use it in GitHub Desktop.
Equal Columns
/*Keeps columns equal height*/
//Modified from http://www.cssnewbie.com/equal-height-columns-with-jquery/#.UtX2EJ5dXTc
function equalHeight(group) {
group.each(function(){
$(this).css('height', 'auto');
})
if ($(document).width() > 600) {
var tallest = 0;
group.each(function() {
var thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.css('height', tallest + 'px');
} else {
group.each(function(){
$(this).css('height', 'auto');
})
}
}
//Use like this:
$(document).ready(function(){
/*Keeps columns on homepage equal height*/
equalHeight($('.columns1'));
equalHeight($('.columns2'));
$(window).resize(function(){equalHeight($('.columns1'));});
$(window).resize(function(){equalHeight($('.columns2'));});
});
/* HTML is like:
<div class='columns1'>stuff...</div>
<div class='columns1'>stuff...</div>
<br />
<div class='columns2'>stuff...</div>
<div class='columns2'>stuff...</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment