为什么有时父元素无法包含子元素?
在css布局中,有时会出现以下现象:父亲元素可能为0x0,而子元素实际上是有尺寸的。总结一下有以下几种场景会导致这种情况发生:
-
If the child uses
position: relative; top: 200px
and move away from the parent. -
If the child does something similar using a negative margin. (similar to 1)
-
If the child is a float, and there is no clearing or some kind of clearfix, such as the newest method of making the parent
overflow: auto
, then the parent will not enclose the floated child.
详情参考so: https://stackoverflow.com/questions/4212940/css-why-some-parent-divs-area-didnt-cover-child-div
积小流以汇江海,细微做起