captured sparks

Equal height columns

One of the common issues that has plagued web designers is how to ensure that a sidebar column with a background colour will fill the height of the page when a second column is much longer. One of the most used options is Faux Columns by Dan Cederholm.

I’m going to show you how to quickly achieve identical height columns using jQuery.

We start with a simple layout:

<div id="main">
  <div id="sidebar">
     Lorem ipsum..
  </div>

  <div id="content">
    Lorem ipsum...
  </div>
</div>

We can then use the following jQuery code to ensure that the sidebar is always equal to the height of the content column:

var mainHeight = jQuery('#main').height();
  if (mainHeight > 280) {
    jQuery('#sidebar').css({
      height: mainHeight
    });
  } else {
  };

This grabs the height of the #main div and if that height is greater than 280px, dynamically adjusts the height of the sidebar to match.

You can talk to me, or trackback from your own site. Or, if you're looking for more things to read? Why not check out the Archive.

  1. Thanks for this solution! very nice.

Talk to me