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

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

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

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

</div>
</body>
</html>

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

#main {
float:left;
width:366px;
margin:32px;
padding: 0;
}

#sidebar {
float:right;
width:144px;
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.

Advertisements

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

  1. Sascha says:

    Wow, thank you. This has helped me quite a bit! Thanks!!!!

%d bloggers like this: