html - 两个边距彼此重叠的 div,其中只有一个似乎有边距

标签 html css

我有这个代码:

<div class="left bigbox"></div>
<div class="left">
    <div class="smallbox"></div>
    <div class="smallbox"></div>
</div>
<div class="left tallbox"></div>

.left{float:left}
.bigbox, .smallbox, .tallbox{margin:5px;background:#000;}
.bigbox{width:490px;height:370px;}
.smallbox{width:240px;height:180px;}
.tallbox{width:240px;height:370px;}

所以两个相互重叠的小盒子都有 5px 的边距。所以它们顶部和底部之间应该有 10px 的边距。但出于某种原因,只有 5 像素的边距。有人知道为什么吗?

http://jsfiddle.net/4JAdx/

最佳答案

这称为 margin 崩溃。在第一个 .smallbox 上添加底部边距以修复它:http://jsfiddle.net/y8cGe/ .

.smallbox:first-of-type {
    margin-bottom: 10px;
}

关于html - 两个边距彼此重叠的 div,其中只有一个似乎有边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24814466/

相关文章:

html - 排队脚本未显示在头部

html - 数据列表奇怪的行为

javascript - 如何更改页面和维护导航栏

css - Bootstrap-Sass:使用另一个变量覆盖变量

javascript - 链接滚动到顶部并且不跟随移动设备上的目标

html - 为什么top是:inherit; Behaving This Way?

html - 是否有用于转义 HTML 的 Delphi 标准函数?

javascript - jQuery点击改变颜色

html - 设置表格的最大宽度

css - 如何删除最后一个 child 的底部边框