在这种情况下,我希望第一个div的底部边框和第二个div的顶部边框之间的垂直间距为45px,但是浏览器折叠了底部和顶部的margin。
在浏览器中显示的第一个div的底部边框和第二个div的顶部边框之间的有效间距为25px。
理想情况下,边框应该防止margin折叠。这里有什么错误吗? 我没有应用任何定位或浮动。
HTML
<body>
<div><p>A</p></div>
<div><p>B</p></div>
</body>
CSS
div{
width:200px;
height:200px;
}
div:nth-child(1){
background-color: #F52C6F;
border-bottom: 10px solid black;
margin-bottom: 20px;
}
div:nth-child(2){
background-color: #0ECCCC;
border-top: 10px solid yellow;
margin-top: 25px;
}