如图,为什么我给p标签元素设置的margin-top会作用在p上面?
<p class="test">
<p class="para">this is a para</p>
</p>
* {
padding: 0;
margin: 0;
}
.test {
position: relative;
height: 400px;
width: 1000px;
margin: 0 auto;
margin-top: 0;
margin-bottom: 0;
background-color: #DCF1B8;
}
.para {
width: 20%;
margin-left: auto;
margin-right: auto;
background-color: #734E4E;
height: 50%;
margin-top: 100px;
margin-bottom: 100px;
}
CSS外边距合并
http://www.w3school.com.cn/css/css_margin_collapsing.asp
因此推荐尽量优先使用padding来控制间距