The W3C float specification requires that a cleared element shall stay below all previous floats. There are no exceptions to this requirement! “Previous” in this case means any float that comes earlier in the source document.
My question is, How to properly clear a floated div that is inside of the parent div also floated?
css:
<style type="text/css">
body {
background-color: #ceefde;
background-image: url(images/pawsw2e.gif);
}
.maindiv1 { margin-left:auto; margin-right:auto; display:block;
text-align:left;
float:left;
width:10%;
/*padding-left:10%;*/
border:5px solid #90F;
font-size: large;
font-weight: bold; }
.maindiv2 { margin-left:auto; margin-right:auto; display:block;
text-align:center;
width:70%;
float:left;
padding-left:10%;
border:5px solid blue;
font-size: large;
font-weight: bold; }
</style>
HTML:
<body>
<div class="maindiv1">
some<br />
content<br />
</div>
<div class="maindiv2">
<div style="width:40%; float:left; text-align:center; margin-left:auto; margin-right:auto; display:block; border:solid #C00;">
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
</div>
<div style="width:40%; float:left; text-align:center; margin-left:auto; margin-right:auto; display:block; border:solid #0C0;" class="clearfix" >
testg<br />
testg<br />
testg<br />
testg<br />
testg<br />
testg<br />
</div>
<div style="clear:both;"></div> <!--Is this line ok if I want some regular content on next line?-->
<p style="text-align:left;">hi</p> <!--Note main div is also floated left-->
<div style="width:40%; float:left; text-align:center; margin-left:auto; margin-right:auto; display:block; border:solid #C00;">
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
</div>
<div style="width:40%; float:left; text-align:center; margin-left:auto; margin-right:auto; display:block; border:solid #0C0;">
testg<br />
testg<br />
testg<br />
testg<br />
testg<br />
testg<br />
</div>
</div>
</body>
</html>
The above works, but is it the correct way to clear just the above div, put some content, then put more floated div's?
A page that show what I'm trying is:
[http://www.taylorjoneshumane.com/zevents_new3.html](http://www.taylorjoneshumane.com/zevents_new3.html)