Two-column layout: fine in Firefox, Safari and IE7, breaks in IE6

January 18, 2007

The code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" lang="en" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">@import url(css/styles.css);</style>
<div id="container">
<div id="main">
<p>Lorem ipsum dolor sit amet, ...</p>

<p>Maecenas a enim vitae est ...</p>

<div id="sidebar">
<p>Lorem ipsum dolor sit amet, ...</p>


The CSS:
#container {
position: absolute;
top: 0;
left: 50%;
width: 606px;
margin-left: -303px;

#main {
padding: 0;

#sidebar {
margin:32px 32px 32px 0;
padding: 0;

Looks fine in Firefox (and IE7 and Safari):

Two-column layout in Firefox

But breaks in IE6, with the second column dropping below the first one:

Two-column layout in IE6

Why does this happen?
The reason the layout breaks in IE6 is due to the IE Doubled Float-Margin Bug.

The fix
Add the declaration:
display: inline;
to #main and #sidebar.