Intentional use of element not stretching around it's floating child?
As you may know, elements that contain floating elements won't stretch around their child element开发者_如何学Pythons unless you either add clear
elements after them or set the parent's overflow
to hidden
. See example.
My question is, are there any real life scenarios in which one would want to not stretch the parent element around it's children, as in the "Overflow visible" box in the above example?
Interesting thought, but I doubt anyone would want that as first, you can just do a border + padding to reproduce that scenario, and second, the clear thing is actually thought of as a bug/something that isn't the right behavior.
In the real world, if you didn't know any better, you can settle with that "solution" where a box was there that didn't have any height and the element they're containing is showing outside of it, but since you know better, it is better to just do it correctly, meaning, clearing the div, using absolute positioning, or using borders and padding to achieve the same effect.
EDIT
It is not actually a bug but it was the "right" behavior because if float containers cleared themselves, it would propose a much harder problem as discussed in this page: http://css-tricks.com/all-about-floats/
精彩评论