Clearing a floated <li> correctly

Katzenfresser picture Katzenfresser · Feb 5, 2011 · Viewed 8.5k times · Source

i dialy deal with float: left; and the CSS-reset by Eric Meyer with class="clearfix". But there is one special case, i wonder how to clear a floatd element correctly: Within <ul> ... </ul>.

Wrong height of the <ul> though using a clearer. The clearer should be within the <ul>. Let's try ...

Correct height, but the HTML-code ist not valid!

How can i clear the float within the <ul> with valid code?

Thanks, Johannes

Answer

Yi Jiang picture Yi Jiang · Feb 5, 2011

Simply add overflow: hidden to the ul element's ruleset. Search for 'clearing floats' on Google or Stack Overflow for other solutions, though in this case this should be the cleanest.

jsfiddle demo: http://jsfiddle.net/9sxrN/1/