Reputation: 345
Recently I am learning some stuff about CSS,I found some awesome tricks about overflow
:
Set parents of float elements to overflow:hidden
or overflow:auto
can keep parents from collapsing
<div style="overflow: auto;">
<div style="float: left;">Div 1</div>
<div style="float: left;">Div 2</div>
</div>
make two columns have same height,set a big enough padding at the bottom
of each floated element, and countering it with an equal negative margin
at the bottom of the same elements. The trick is to set the overflow
on the parent container to hidden
I can not image how it work,why is overflow
so obscure? someone can explain it?
Upvotes: 2
Views: 40
Reputation: 558
The clearfix behavior you describe in 1 is a well known properties of overflow
as you can see here: https://css-tricks.com/almanac/properties/o/overflow/#article-header-id-6 and http://www.stubbornella.org/content/2009/07/23/overflow-a-secret-benefit/ and this is an expected behavior, since it is part of the CSS 2.1 spec: https://www.w3.org/TR/2004/CR-CSS21-20040225/visudet.html#root-height (see the last sentence of the 10.6.7 'Auto' heights for block formatting context roots paragraph)
The 2 is (as @alohci says in the comment) the overflow: hidden
expected behavior.
For further details you can read the official spec: https://www.w3.org/TR/CSS22/visufx.html#overflow
Upvotes: 1