If you work with css floats much you’ll eventually come across this problem:

float1

2 floated elements inside a container. The container doesn’t expand to contain the floats. There are a lot of solutions to this, such as sticking in an element to clear the floats (bleh) before closing the container, using the :after pseudo-class to inject something to clear the floats, or setting a fixed height for the container, using a min-height workaround – the list goes on. The simple, all-conquering method of getting around this problem? Float the container too:

float2

This article has been copied from http://www.yongfook.com/items/view/81/10-dirty-little-web-development-tricks

Advertisements