Skip to content

Instantly share code, notes, and snippets.

@lukewatts
Last active November 4, 2015 17:54
Show Gist options
  • Save lukewatts/e247822c6e0dcf21acea to your computer and use it in GitHub Desktop.
Save lukewatts/e247822c6e0dcf21acea to your computer and use it in GitHub Desktop.
We've all been in that situation when we have 3 columns of blog posts and each one has varying amounts of content, different sized images etc. This small jQuery function simply gets the tallest element in such a group and makes the rest this height.
<!DOCTYPE html>
<html lang="en">
<head>
<title>A Bunch of uneven columns</title>
</head>
<body>
<section id="latest-news">
<article class="columns">
<p>One lin of text</p>
</article>
<article class="columns">
<p>Two lines of text</p>
<p>Two lines of text</p>
</article>
<article class="columns">
<p>Four lines of text</p>
<p>Four lines of text</p>
<p>Four lines of text</p>
<p>Four lines of text</p>
</article>
</body>
jQuery(document).ready(function($) {
$.fn.normalizeHeight = function() {
var maxheight = 0;
this.each(function() {
if($(this).height() > maxheight) {
maxheight = $(this).height();
}
});
this.height(maxheight);
};
jQuery("#latest-news .columns").normalizeHeight();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment