Nearly every website these days have columns. Since we have grown out of the old table days and into this new era of CSS we tend to over think certain things like how to create two columns side by side which can vary in height, but still appear to be the same height. The solution is so simple its rediculous. We start out with a left column and a right column(could be three columns.. this will work just as easily, but I’ll keep it simple), two div’s floating side by side via float:right; or float:left;. Next we add a left border to the right column, which is the same width and color as the left:
border-left: solid 150px #aaaaaa;
This will shove your right column out of line, but no worries, step three we slide it right back into place. With a negative left margin on the right column we can literally slide the right column back up under the left column:
margin-left: -150px;
So basically we added two lines of code to the independent columns, now it never matters which one is taller, they fill in for each other. A simple Example.
Related posts:




4 Responses
new era
04|Dec|2007[...] Variable Columns with CSS [...]
Bennett
09|Dec|2007This works perfectly if the right column is longer than the left. But if the left is longer, the columns appear unequal heights. Any ideas how to handle this?
trent
09|Dec|2007Well I guess the one small catch is one column has to have the same background as its container(the column with the border should), so you can’t tell it ends. A little misleading but it should still work in most cases.
Eric Sanderson
19|Dec|2010I am a complete novice at web sites and I’m trying to do my first one. I know I am stupid but I hope to learn. I am trying to adjust a two column site but I cannot get the widths of the two columns right. I have Amazon pages but the Amazon search box (which is on the right of their pages) keeps getting hidden under the left hand column. I have tried all ways to sort it without success.
Please help.
Any advise would be greatly appreciated
Eric Sanderson
(A stupid pensioner)