Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple 3-column, pure CSS layout?

Tags:

html

css

One that doesn't require the following:

  1. Reliance on images (i.e. "faux columns")
  2. Some kind of weirdness or "hack" put in specifically for IE
  3. Requires IE to run in quirks mode
  4. Doesn't have strangeness like one of the three DIVs overlapping the others (i.e. "holy grail")
  5. Margins set to high negative numbers placing them well off the viewscreen (again "holy grail" layout)

I can't find a 3-column layout in CSS that doesn't rely on one of the above. And relying on one of the above seems to negate a lot of the advantage of using CSS over tables. I don't want to have to whip out Photoshop and resize an image every time I want to change the width of my left column. And I don't want to have to pull out the calculator to figure out how many pixels off the side of the screen my DIV has to be.

I should mention that I'm looking for an equal-height layout.

Anyone?

EDIT: I'm looking for a width of 100%, with the center column being liquid.

EDIT: I'm also hoping to specify the width of the left and right columns in pixels.

EDIT: Backgrounds can be transparent, but I would like a dividing line between the columns which runs all the way up and down.

like image 764
Sean Avatar asked May 15 '09 09:05

Sean


4 Answers

There is no such thing as "simple" when you talk about CSS.

But there is a simple solution that is cross browser, degrades gracefully and is fully HTML and CSS compliant: use a table with three columns.

Reasoning: DIVs are not meant to have the same dynamic height. Therefore, CSS has no support for this. If you need a block element which makes sure that its children have the same height, then that's what tables are for.

[EDIT] Sorry to offend all you CSS fanatics out there but, frankly, when something is not designed to do something and you abuse it, and it doesn't work, please stop complaining, ok? A DIV is not a TABLE and can't be used as one without relying on hacks.

[EDIT2] As was said already in various places, the reason not to use tables for layout was that, in early times, tables were the only design element and that lead to HTML which had dozens of nested tables. That's bad. But that doesn't mean you must not use a single table to put everything in place and then rely on CSS to make the stuff inside look right.

A brain is like a parachute: It's nice to have but only useful when it's open.

like image 119
Aaron Digulla Avatar answered Oct 22 '22 04:10

Aaron Digulla


You might be able adapt:

http://matthewjamestaylor.com/blog/perfect-3-column.htm

like image 33
Sinan Ünür Avatar answered Oct 22 '22 06:10

Sinan Ünür


I agree with Robert. Due to browsers interpreting CSS rules and rendering the final page differently I doubt you'll find a perfect solution without being more flexible in your requirements.

like image 44
Nick Avatar answered Oct 22 '22 05:10

Nick


You can achive this by using jS.

If you were to create 3 Divs one float left one flot right and the middle as margin left & right with a width to centre it.

Then with a bit of JS each div having their own ID you could calcultate their height set the 2 lowers ones to the highest value.

Pretty simple with Jquery.

like image 1
Lee Avatar answered Oct 22 '22 04:10

Lee