为什么这个margin-top会影响父元素?

正常的margintop应该是影响子元素在父元素的的布局,比如
图片说明
为什么我的这个设置子元素的margintop.反而子元素在父元素中的位置没变,父元素与父元素之间的距离变了
图片说明
两个滚动的页面
图片说明
中间本来应该是没有间距的
图片说明
只有第二页的h2与第二页之间有间距才对
图片说明
基本没有特殊布局

 #resume_contactMe {
    background: url(../img/contact_bg.jpg) no-repeat;
    background-size: 100% 100%;
    opacity: 0.7;}
#resume_contactMe .container-contactMe {
}
#resume_contactMe h2 {
    position: relative;
    width: 360px;
    font-family: sans-serif;
    font-size: 64px;
    line-height: 64px;
    margin: 140px auto 0;
    border-bottom: 2px solid #f9d347;
}

可以通过清除塌陷消除

border可以防止margin叠加,没有border上下存在margin(包括子元素)会叠加margin去最大值
精通CSS里面有提到margin叠加
图片说明
图片说明
图片说明

我必须吐槽一句,各位大佬的回答能不能尽量精简明了一点,从别的地方直接粘贴一大段代码过来的话让提问者情何以堪,花费大量时间才解决一个问题,拖慢了效率

*{ margin: 0; padding: 0; } .father{ /* height: 100px; */ height: 50px; // 正确方式 父级高度 = 父级原高度 - padding-top background: red; padding-top: 50px; // padding-top = 你想要margin-top的值 } .son{ height: 50px; background: green; /* margin-top: 50px; */ // 如果你直接这里设margin-top的话是因为P作为DIV的第一个子元素,所以会影响到父级 }



我是儿子


我是爸爸