Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing a floated <li> correctly

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

like image 412
Katzenfresser Avatar asked Feb 05 '11 00:02

Katzenfresser


People also ask

How do I clear a float?

This is default When clearing floats, you should match the clear to the float: If an element is floated to the left, then you should clear to the left. Your floated element will continue to float, but the cleared element will appear below it on the web page.

What is clearing floats in CSS?

Clearing Floats. Clearing a float means clearing away all subsequent content so that the element is still floated but is not surrounded by the other elements. The clear property takes a value of left, right, or both.

What is the difference between left float and right float clear?

both - The element is pushed below both left and right floated elements inherit - The element inherits the clear value from its parent When clearing floats, you should match the clear to the float: If an element is floated to the left, then you should clear to the left.

How to clear float on parent element of an element?

you can clear float by giving overflow:hidden; on parent element. check the DEMO. Like in your case use in on section element. Down voter please explain why -1 .


1 Answers

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/

like image 177
Yi Jiang Avatar answered Oct 06 '22 22:10

Yi Jiang