首页 > 其他 > 详细

margin-top 为什么会影响父元素的 margin-top

时间:2016-05-09 12:32:09      阅读:199      评论:0      收藏:0      [点我收藏+]

 1.原因:

 In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.

----所有毗邻的两个或更多盒元素的margin将会合并为一个margin共享之。毗邻的定义为:同级或者嵌套的盒元素,并且它们之间没有非空内容、 Padding或Border分隔。

2.解决方法:

  1、修改父元素的高度,增加padding-top样式模拟(padding-top:1px;常用)
  2、为父元素添加overflow:hidden;样式即可(完美)
  3、为父元素或者子元素声明浮动(float:left;可用)
  4、为父元素添加border(border:1px solid transparent可用)
  5、为父元素或者子元素声明绝对定位

 

margin-top 为什么会影响父元素的 margin-top

原文:http://www.cnblogs.com/zouqin/p/5473277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!