Thursday, July 24, 2014

CSS > overflow: hidden

This css property is so magic:

1. When a container contains only float elements, it'll collapse as we all know. 
Normally, we would add a
element with "clear: both;" to fix it(bad) or use div:after with 
"clear: both;"(better). 
Other than these solutions, we can simply add "overflow: hidden;" to the container and problem solved!

2. When a
is added after a float element, the div's width will be 100% cause float element is out of the normal flow.

If you want the div to be exactly put after the float element, add "overflow: hidden;" to the div.




So the basic idea here is that "overflow: hidden;" will create a new BFC(Blocking formatted Content).

No comments:

Post a Comment