Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "overflow: hidden" clears a float?

Tags:

The question is simple and short: why does overflow: hidden; clear floating? I looked in to the w3 standard documentation and it did not imply anything.

like image 473
Tower Avatar asked Feb 05 '11 22:02

Tower


People also ask

Why does overflow hidden clear floats?

The reason why the wrapper doesn't stretch to contain its floats by default is because the floats are taken out of the normal flow of the wrapper, so the wrapper acts as if they were never there. If there is no other content in the wrapper, that means the wrapper won't have any height.

What happens if we use overflow hidden?

hidden - The overflow is clipped, and the rest of the content will be invisible. scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content. auto - Similar to scroll , but it adds scrollbars only when necessary.

What does clearing a float mean?

To clear a float, add the clear property to the element that needs to clear the float. This is usually the element after the floated element. The clear property can take the values of left , right , and both . Usually you'll want to use both.

Why do we clear floats CSS?

Purpose of clearing floats in CSS: We clear the float property to control the floating elements by preventing overlapping. On our webpage, if an element fits horizontally next to the floated elements, unless we apply the clear property same as float direction then the elements will be a move below the floated elements.


1 Answers

Because you establish a new Block Formatting Context when using overflow with anything ofther then visible (link to the w3.org specs).

like image 137
ChristopheD Avatar answered Oct 11 '22 02:10

ChristopheD