Last active
November 4, 2015 17:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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