我有两个div,一个“容器”和一个“内容”。如果内容在容器内,则适合容器。CSS保证金不根据母公司
#container {
display:block;
width:300px;
margin:auto;
background:green;
}
#content {
display:block;
margin:20px; /* HERE IS THE ERROR */
background:yellow;
}
顶部和底部边距不在父项内,但左侧和右侧均为。
为什么会发生这种情况?
余量塌陷。使用容器中的填充来定位内容。或者确保容器没有设置上边距。 – ProfileTwist