【发布时间】:2016-06-23 14:11:01
【问题描述】:
我尝试在父级内部的 div 上添加 margin-bottom,但它显示为父级的 margin-top。为什么?
HTML:
<div id="wrapper">
<div id="content">
<div id="box"></div>
</div>
</div>
CSS:
#wrapper{
border: 1px solid #F68004;
}
#content{
background-color: #0075CF;
height: 100px;
}
#box{
margin-bottom: 50px;
}
我的预期:
我得到了什么:
更新:
我可以解决这个问题,但我不知道为什么该代码不起作用?谁能解释一下?
更新 2:
看起来大多数答案都说它是因为边距崩溃而我的问题与this 重复。但请注意,我设置了 margin-bottom 而不是 margin-top。我还阅读了有关折叠边距的信息,但我找不到任何规则说边距底部可以变成边距顶部。谁能指出我?
【问题讨论】:
-
我又更新了我的问题,谢谢!
-
@MinhHoang 如果您的问题解决了。您应该通过单击正确的符号来接受任何解决您问题的答案。
-
@ketan 我的问题还没有解决。
-
@Pete 我把 margin-bottom 但不是 margin-top