
November 22nd, 2012, 01:10 AM
|
|
|
When you float an element, it essentially removes it from the boundaries of your containing element so your header won't 'stretch' to match the floated elements inside it unless you clear after the floated elements.
Now I know I will probably get shot down in flames for this, but the simplest way to do this that I have been using for years is just to create a class
Code:
.clear { clear: both; }
And then apply that either as a div on its own after the floated elements and before the close of the header, or add the class to the header itself.
Code:
<div class="header clear"><!-- Add here -->
<ul id="nav">
<li><a href="#">work</a></li>
<li><a href="#">about</a></li>
<li><a href="#">contact</a></li>
</ul>
</div>
<div id="main">
<div class="leftCol"></div>
<div class="rightCol"></div>
</div>
<!-- OR add here -->
<div class="clear"></div>
</div>
The more 'up to date' method is to use clearfix
Code:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
And again, add this class to the parent element, in this case your header (as I did above)
|