Clearing Floats in CSS
A common problem with float-based layouts is that the floats’ container doesn’t want to stretch up to accomodate the floats. If you want to add, say, a border around all floats (ie. a border around the container) you’ll have to command the browsers somehow to stretch up the container all the way.
I’ve found myself searching for this repeatedly so I’m linking to it here for posterity. The gist of it is to add a width and overflow property to the div containing the floating elements, like so:
div.container {
overflow: hidden;
width: 100%;
}
Find This Article Useful?
Related Articles
About this entry
You’re currently reading “Clearing Floats in CSS,” an entry on MirthLab
- Published:
- Wednesday, July 1st, 2009 at 4:24 pm
- Author:
- Mark Quezada
- Category:
- Web Development

No comments
Jump to comment form | comments rss | trackback uri