It has been advocated many times that tables shouldn't be use in HTML for layout purposes. This page shows one way to create a 3 columns layout using CSS only.
Please send comments and suggestions to Dominique Hazaƫl-Massieux. Spanish and a French translations of this article are available.
HTML is a structural language, which means
it is - or should be - used to add structure into a text through
tags. The table
tag should then only be used to format
data into a table to relate columns with rows.
But since the apparition of tables in HTML, it has been very often used for layout purpose, usually split a web page into columns. Besides the fact that it breaks the meaning of HTML, it doesn't help either in various cases that we could summarize by the difficulty to parse or render a table in some context (disabilities, view port restrictions, ...).
This document describes one way to create a 3 columns layout and links to other layout techniques.
The technique described below is the one used in the page for new W3C users and allows to build a 3 columns layout, with the following features:
It's ideal for homepages since it allows to have a complete text in the center and nice lists of links on the side.
One of the restriction is that it won't work for too bad CSS implementations, but it will degrade nicely into a traditional vertical layout.
This layout is applied to this page itself so that you can get an idea of what it produces.
The idea is to crop the main division on the sides using the
margin-left
and margin-right
properties, and
then to position each side columns using
position:absolute
, and set the top left corner and top
right corner coordinate to (0,0).
To prevent bad CSS implementations to read the stylesheet, just
call it through <style type="text/css">@import
url('your-stylesheet-url');</style>
.