Rates To Travel - Free hotel comparison tool

Back when tables were used for layouts, creating equal height columns was very simple. All you had to do was create three cells in a row and you have a layout with equal height columns. The method for creating equal height columns isn’t as straightforward when you use CSS for layouts.

This article discusses some methods to create equal height columns that work on all major web browsers (including the infamous IE6). All of these methods show how to create a three column layout.

Create a layout in which all the three columns assume the height of the tallest column.

Method 1: Using display: table Attribute

In this method we use a list or one div enclosing a set of <div>s (one for each column). The enclosing div is given a display: table attribute and each enclosed div is given a display: table-cell attribute.

I’ll discuss this with an example:

Here’s the markup for this technique

  1. <div class=”base”>
  2. <ul class=”base-row”>
  3. <li class=“cell1″><div class=“content1″ >…..Lots of  Content….</div></li>
  4. <li class=“cell1″><div class=“content2″>…..Lots of  content….</div></li>
  5. <li class=“cell1″><div class=“content3″>…..Lots of  content….</div></li>
  6. </ul>
  7. </div>
<div class=”base”>
 <ul class=”base-row”>
 <li><div >.....Lots of  Content....</div></li>
 <li><div>.....Lots of  content....</div></li>
 <li><div>.....Lots of  content....</div></li>
 </ul>
 </div>

Here’s the CSS

  1. .base {
  2. /*make it 100% width and a minimum of 1000px width*/
  3. width: auto;
  4. margin-left: 0px;
  5. margin-right: 0px;
  6. min-width: 1000px;
  7. padding: 0px;
  8. display:table;
  9. }
  10. .base-row {
  11. Display: table-row;
  12. }
  13. .base li {
  14. display: table-cell;
  15. width: 33%;
  16. }
  17. .cell1 {
  18. background-color: #f00;
  19. }
  20. .cell2 {
  21. background-color: #0f0;
  22. }
  23. .cell3 {
  24. background-color: #00f;
  25. }
.base {
 /*make it 100% width and a minimum of 1000px width*/
 width: auto;
 margin-left: 0px;
 margin-right: 0px;
 min-width: 1000px;
 padding: 0px;
display:table;
 }
.base-row {
 Display: table-row;
 }
.base li {
 display: table-cell;
 width: 33%;
 }
.cell1 {
 background-color: #f00;
 }
.cell2 {
 background-color: #0f0;
 }
.cell3 {
 background-color: #00f;
 }

Advantage:

It is very simple and easy to implement. It is far simpler than most other methods. This can save you a LOT of headache and time.

A margin (the equivalent of a cellspacing in table layouts) cannot be applied to each cell. This can be overcome by using a border of white color (or your background color) of a suitable width to mimic a cell spacing.

Disadvantage:

This method doesn’t work on IE7 and below. It may be a long time (when IE7 becomes the new IE6 or IE5) before we can safely use this technique. But it is useful when you can be certain IE7 will not be used by your audience such as in corporate Intranets.

Check more methods on: http://buildinternet.com/2009/07/four-methods-to-create-equal-height-columns/

Related Resources: