Introduction to CSS Positioning Properties Part 2 - The "clear" property (Page 2 of 6 )
This property is used to give control of an element that appears after a floated element. Setting this property on the selected element will ensure that it will appear below any floated boxes that come before it. The possible values taken are the following:
The selected element will be displayed below any left-floating boxes being rendered before it.
The selected element will be displayed below any right-floating boxes being rendered before it.
The selected element will be displayed below any left-floating or right-floating boxes being rendered before it.
The selected element will not clear any floating boxes that come before it.
Let's show some examples that implement this property. Let's suppose that we've created a simple two-column layout, displaying a left-floated navigation bar, and a main container, floated to the right.
We need to be able to display a footer section after they're visually rendered. Just utilizing the "clear" property, that section is properly located.
And the markup would be the following:
As we can see, the "footer" section clears the floated elements, and is displayed in the right way. There are many websites using these kinds of hooks to nicely implement page layouts. In fact, the floating approach is quite powerful for achieving several page layouts. It makes it even easier to emulate <table> designs, and the code is a lot more concise.