I sometimes wonder if the most hated aspect of design is the three column layout. Or really, any layout where your primary content is in the middle, directly surrounded by two far less important segments. Strangely enough, this seems to often be the most used design type on the web. Three columns functions well for holding a wealth of useful (or useless?) information in a nice organized format. Right...?
Personally, I wouldn't mind getting rid of them all together. I hate having extra mark-up for the sake of design, and I suffer for that personal bias constantly. The most common technique that I know of is putting an extra wrapper around your content and third column and doing some absolutely wonky things with floats. And then, hoping your revolver in your desk drawer is full of bullets when it's insisted upon that the site's layout, at the very least, functions in IE6.
And, on a side-note, might I ask... why does anything need to function in IE6? Why do we even care about IE6? And even more importantly, why are people still installing old versions of Windows XP that they dusted off out of their desk drawer (where it sits right next to that revolver) and then not upgrade their browser? You don't have to use Firefox, Safari, Opera, Chrome heck... even IE7 is better than that.
Back to the layout. It's been a goal of Kyle's and mine to find some way to do a 3-column layout that works without a wrapper. One of the nice things about working in this field is that the job is always challenging, and there's a new problem to solve around every corner. Of course, until you're unable to solve it and then you go looking for that revolver... again. How many bullets are left at this point? (And on that note, don't open this site in IE6 or you'll lose one more).
We tried a few funky things with some negative margins using a percent base, and then - of course- when trying to recreate what was done after hours of long consideration (and just plain guess work), it ended up being impossible to do again.
A couple weeks ago, though, I was working on one of these Banes of Janae's Existence, and trying then to debug the horrendous thing in, yeah, you guessed it and I'm not going to say... and Kyle pops out of the wood work and says "Hey, try this!"
Have I ever mentioned that I'm jealous of his timing? I am.
The basic premise:
- Have a single wrapper named content or whatever you like.
- Make sure that it has a right padding as wide as the third column and an overflow: hidden to clear floats
- Okay, this is where it gets confusing. Float the first column to the left and give it a margin-left large enough for the second column.
- Float the second column to the left, giving it a negative margin-left that is the sum of the first and third columns.
- Float your third column to the right and give it a negative margin-right that is the width of itself.
Note that whenever I'm talking widths here, I'm considering the actual width of each column plus whatever padding is on it. Remember, also, that each column must have a specified width. I haven't fiddled with it too much in percentages or ems, but if anyone else does, I'd love the feedback.
Here's the example with the CSS.
Three sites later, and it still works like a charm. No extra mark-up, just content box and the three columns inside it, and not even the Dean Edwards script needed for anything but PNGs in IE6. Life is good. Even if I didn't solve it myself.