
Originally Posted by
Michael Morris
I presume you're wanting the right div to not wrap around the floating div and stay in its own column. This is a fairly common use case, and the starting HTML at a base will look something like this.
I feel that I should point out that although that method appears to work well it is slightly flawed in that you can no longer have any elements in the main column that are set to clear:both. If for example you have a floated image in the main column and you want to clear the content that follows it then you end up with all the rest of the content down below the sidebar. You actually clear all floated elements in the html before because the article element does not create a new "block formatting context".
You would need to nest an inner div inside the article element and set it to be floated and 100% wide and then keep all the inner content inside that.
You can see the difference here:
e.g.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
section { padding-left: 200px; /*width of the nav */ }
nav {
float: left;
width: 200px;
margin-left: -200px;
background:red;
padding-bottom:100px;
}
article { width: 100% }
footer { clear: both; }
.inner {
width:100%;
float:left;
}
</style>
</head>
<body>
<header></header>
<section>
<nav>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
</nav>
<article>
<div class="inner">
<p>This is a test</p>
<p>This is a test</p>
<p style="float:left">This is a float</p>
<p style="clear:both">Clearing element</p>
<p>This is a test</p>
<p>This is a test</p>
</div>
</article>
</section>
<footer>footer</footer>
</body>
</html>
If you don't need visible overflow then the method Ralph suggests will do all that automatically anyway but will need zoom:1.0 for ie7 and under (or a valid property that gives layout).
Bookmarks