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

来源:互联网 发布:ipad提示无法加入网络 编辑:程序博客网 时间:2024/05/17 08:43
在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

原创粉丝点击