為什麼有時父元素無法包含子元素?

世有因果知因求果發表於2017-05-31

在css佈局中,有時會出現以下現象:父親元素可能為0x0,而子元素實際上是有尺寸的。總結一下有以下幾種場景會導致這種情況發生:

  1. If the child uses position: relative; top: 200px and move away from the parent.

  2. If the child does something similar using a negative margin. (similar to 1)

  3. 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

相關文章