在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