这个是css代码:
<style>
.wrapper{
position: relative;
background-color:aquamarine;
}
.header{
border: 1px solid red;
position: absolute;
background-color:aquamarine;
}
.baidulogo{
margin-top: 200px;
text-align: center;
border: 1px solid black;
background-color: #3388ff;
}
baidulogo img{
width: 270px;
height: 129px;
}
</style>
这个是html部分
<div class="wrapper">
<div class="header">
<sapn class="nav">新闻</sapn>
</div>
</div>
<div class="baidulogo">
<img src="bd_logo1.png">
</div>
问题:为什么改变.header的margin-top值.header的位置也跟着改变,是什么原理?
由于header是绝对定位提升层级,.baidulogo会挤上去造成 margin-top传递给父级。关于margin-top折叠可以参照 https://www.w3cplus.com/css/u...