If you feel skeptical about my claim, I don't blame you. Like many web developers I too have tried to create 3 column layouts using the various types witchcraft found on web developer blogs:
I'll call this technique the "float everything and clear" approach. I don't claim to have invented it, its just the way I've learned to do it over 4 years.
It works predictably in Safari, Firefox, IE7, IE6. It belly laughs at the the task of switching from a 4 column, to 3 column to 2 column layout. ITS NO FUSS! It contains no hacks, no browser specific code, no positioning, no negative margins. Just give your columns a width, make sure they add up to the total width of the container, and move on.
Here's a demo, and explanation. The demo demonstrates the the technique with 4 layouts: 2 column left, 2 column right, 3 column, and 4 column. It also demonstrates those 4 layouts surviving fluid width, 1000px, 800px, 600px respectively. The demo site files are attached at the bottom. Enjoy.
| Attachment | Size |
|---|---|
| simpleLayout.zip | 3.14 KB |
Comments
http://www.nicklewis.org/simp
http://www.nicklewis.org/simple-layout: Page could not be found
first multi column attempt
I hate to say this, but I think this is what I was looking for. Everyone shows the 3 columns and they seems a little different and as a newbie sometimes I don't know why.
Not all sites want to nit pick and add lots of borders and colors, etc. Sometimes you just want to put some information in tabular form and I am having a hell of a time getting my two right columns where they belong, no problem with the two left ones for some reason.
I pray this is my solution because it's driving me buggy. Sometimes it's best to keep it simple and only make it complex if absolutely necessary.
If IE would understand the
If IE would understand the
display: tableanddisplay: table-cellproperties... Everything would be great.CSS2 is very good for layout, too, but damn IE does not understand the crucial display property.
Want no hassle? Use Faux
Want no hassle? Use Faux Absolute Positioning: http://alistapart.com/articles/fauxabsolutepositioning/
I've never seen a more stable layout technique in my life, it cannot break in any browser from IE6 up. It has a couple of quirks to watch out for, but they're easily avoidable and hardly an issue.
We use to use a float-left-and-clear layout in our base theme, but since we always had 3-4 different people skinning sites the layout would almost always fall apart in testing. It was too fragile. Ever since I introduced FAP to the base theme we haven't once had a sidebar fall out of place.
Well, while your layout
Well, while your layout technique certainly works very well for many cases, it is by all means not the layout technique to rule 'em all.
Several points to consider:
1) One of the most common scenarios is to have two fixed-width sidebars and a fluid center column. Your technique doesn't allow that.
2) Equal Height columns. The background-color hack you mentioned in your comment to "a passing drifter" certainly doesn't hold true for many cases. Imagine graphical borders between the central column and the sidebars, a very common usage scenario (e.g. Garland). This is not possible with your technique, at least not if you aren't using a fixed-with central column.
3) Source-ordering. While the SEO point might be kinda moot, source ordering is still an important point to consider when thinking about constrained devices, e.g. small form factor devices that therefore disable some CSS properties (like float) to make the content fit the screen - in many scenarios you'd want the main content to come first there.
While I am definitely no fan of absurdly complicated layout techniques, I mostly agree with Steven here - unfortunately (mainly because of poor browser support, partly resulting from the history of using tables for layout purposes) there are many cases where we need more advanced methods.
In short - the most simple layout one can do with tables - two fixed width sidebars, a liquid center column and a footer that spans all three columns, is very unfortunately still not perfectly possible just with CSS. I tried many methods, I tried to combine them, but so far there simply is not one technique that works for this scenario in a general use case (e.g. a CMS default theme), all browsers and without JavaScript. The One True Layout by positioneverything is most likely the closest, and I implemented it for Drupal, but without many ugly hacks it unfortunately fails as layout technique for a general purpose theme because of its issues with anchors and a few other glitches which I don't remember right now out of my head.
There, I renamed the article
There, I renamed the article Multi-Column CSS Layouts for Slackers. I'm a proud slacker. I have no problem asking a designer to alter their mockups so that a layout can take an hour to get right, instead of 10 hours. Sometimes spending 10 hours to get *just* the layout right is warranted, but usually there's better things to focus on first.
Just MHO.
Well, I didn't want to sound
Well, I didn't want to sound that critizing actually - I fully agree with you that there are many situations where it is much simpler/better/easier to just use a "simpler" layout instead of having to deal with all these difficulties that some specific layouts require.
ha, no no no, the title was
ha, no no no, the title was too grandiose anyways. Appreciate the disagreement regardless.
As mentioned by Steven, your
As mentioned by Steven, your layout technique doesn't allow you to mix fluid and fixed with columns.
Also, the content div (center) should appear above the left and right in the source code.
Check out layout gala: http://blog.html.it/layoutgala/ for some rock solid multi-column templates.
Fluid width content is
Fluid width content is overrated. Its rare to see a good looking site use it. Do not remember a single design I've ever gotten where the designer said, "Okay, and I want all the text to expand into widest possible area".
.column { float:
.column {
float: left;
}
/* Widths add up to wrapper width */
.column-first {}
.column-second {}
.column-third {}
...
Some nuances
I think this blog post needs some nuances. You make it sound as if everything beyond floated columns is unnecessary bloat and that somehow everyone has been barking up the wrong tree with advanced CSS techniques/hacks.
"The byzantine two column layout wrapped within a two column layout technique"
"The absolutely positioned nightmare"
Both of these techniques are used to achieve layout-independent ordering of the HTML (e.g. main content before sidebars). Depending on the content and audience, this can be important.
"The arcane negative margin trick"
This is normally used to combined fixed-width sidebars with a fluid center column, whereas your structure only does fully fixed or fully (proportionally) fluid.
You also conveniently gloss over the fact that in your technique, due to browser rounding differences, you often need to set the width of the final column to a fraction less of what it should be, resulting in an unsightly gap to the right in many cases.
Not to mention, layouts are always easier in mockups like yours, because you're not actually styling them. For example, in the case of Garland, the page's structural CSS had to be redone from scratch because the simplest, cleanest approach would not render the main background images correctly in both IE6 and IE7 – even though the content inside was fine. If you examine Garland closely, you can see that the two sidebars (left and right) use a different way of sitting next to the main content for this reason.
To answer the issue of equal height columns, as far as I know there is only one technique that somewhat works with floated columns: the trick is to give each column a huge bottom padding and an equal but opposite negative bottom margin. Then, set the layout container to "overflow: hidden" to trim off the bits that stick out. Unfortunately, this technique has several issues that make it impractical in generic page layouts in CMSes.
In conclusion, I wouldn't say the floated-columns approach is the one technique to rule them all, no. A better avenue to explore is CSS2 table display modes with alternate IE6/7 CSS: this is future-proof and ensures the hacks can be phased out eventually. At the end of the day, floats were never meant as column containers in the first place, and their use as such is an abuse of CSS.
Percentages
You'll want to read this:
http://ejohn.org/blog/sub-pixel-problems-in-css/
That explains why 25/25/25/25
That explains why 25/25/25/25 with no width set breaks in IE. I guess it would break by the 6th in firefox, and so on...
Never really understood what
Never really understood what all the fuss is about with these columns. Float'em and calculate widths.
You could however stumble upon the need to equalize their heights. Then you'd probably have to go with the negative margins
I mostly bring it up because
What about repeating background images?
I mostly bring it up because I see so many themes using complex multi-column methods that aren't required by the design. A simpler solution would make them more robust, and easier to work with.
Well, multi-column layout are
Well, multi-column layout are not the problem. The problem is to get the column have the same height.
Oh that one's easy, take this
Oh that one's easy, take this site for example:
http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/
Just make:
#content {
background-color:#eeeeee;
}
#content #center {
background-color:#ffffff;
}
Or in the rare case that you have to have solid columns,I've never seen what is so bad about doing this.
$('#left').height($('#center').height());Especially given the ease with one introduces bugs into the alternatives. Adjusting a few pixels ends up causing you to have to adjust additional pixels in 3 other places. This gets especially troublesome, with say -- a drupal theme -- where there might be 3 columns, 2 columns, no columns, 5 columns?
And what of all the weird counter intuitive things that you have to do for IE explorer support? Usually, when I don't understand what the use is of a CSS property, I delete it -- makes my life easier -- not so with convoluted 3 column methods. Sometimes a {margin:0 -1px;) is all that is keeping the poor layout together.