CSS: 3 Columns Page Layout Tutorial

, , …,
Want to master JavaScript in a week? Buy Xah JavaScript Tutorial.

Here's how to create a 3-columns layout using CSS.

CSS 3 columns layout
CSS 3 columns layout. (see raw HTML rendered example)

Create 3 div tags, and set each's width.

Here's the HTML code:

…
<body>
<div id="main">…</div>
<div id="panel-left" class="mypanel">…</div>
<div id="panel-right" class="mypanel">…</div>
</body>
…

Here's CSS code:

#main {
margin-left:20%;
margin-right:20%;
background-color:LightYellow;
}

#panel-left {
left:0;
background-color:yellow;
}

#panel-right {right:0;
background-color:pink;
}

div.mypanel {
width:20%;
position:absolute;
top:0;
}

For the main container, specify margin-left and margin-right. This will fix the main panel into a narrow central column.

For the left panel, specify a width that is the same as the main's margin-left, and, specify position:absolute; left:0. This will fix the panel on the left side with a fixed width. Similar for the right pane.

You can also add margin:1ex and or padding:1ex. 〔➤ CSS Margin vs Padding

Any text that is not in one of the main or panel div container, will be left on the bottom.

Here's a test page you can view source: HTML: Tableless Layout with CSS: test page.

blog comments powered by Disqus