为什么有时父元素无法包含子元素?

在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

posted @ 2017-05-31 21:26  世有因果知因求果  阅读(527)  评论(0编辑  收藏  举报