Sorry, I found the answer here:
[url]http://www.positioniseverything.net/easyclearing.html
I have come across a problem with floating elements in divs. For some reason the containing div will not adjust to the size of the floating element, so it will protrude from the containing div and all parent divs.
I have tried it in both IE 6 and Firefox 1.5.
Here is an example of the problem:
[code=html]<!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”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>CSS test</title>
<style type=”text/css”>
h1 {
margin: 1em;
}
p {
margin: 1em;
}
div {
border: 1px solid #000;
margin: 1em;
}
#float {
width: 100px;
height: 500px;
background-color: #F00;
float: right;
}
</style>
</head>
<body>
<div>
<div>
<div>
<div>
<h1>CSS test</h1>
<div id=”float”></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
</div>
</body>
</html>
Does anyone know how to make the containing div adjust to fit the contained floating element?