css中父元素占用了子元素的margin-top

参考博客:

http://blog.csdn.net/zhouyongwinner/article/details/43941733

http://blog.sina.com.cn/s/blog_673ee2b50100lxrb.html

父元素包含一个子元素,只给子元素设置margin-top,会发现margin-top加在了父元素上。这是什么原因?

一个盒子如果没有上补白(padding-top)和上边框(border-top),那么这个盒子的上边距会和其内部文档流中的第一个子元素的上边距重叠。

温习一下几个属性:

margin:几个元素之间的间距

border:指元素自己的边框

padding:俗称上补白,背景会在这里显示

content:真正显示内容的地方,俗称width,height。

你可能感兴趣的:(css中父元素占用了子元素的margin-top)