
如图,为什么我给p标签元素设置的margin-top会作用在p上面?
this is a para
* {
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;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
CSS外边距合并
http://www.w3school.com.cn/css/css_margin_collapsing.asp
因此推荐尽量优先使用padding来控制间距