gpt4 book ai didi

css - div 在另一个有 margin top 的 div 之上有 margin bottom,只有 1 margin

转载 作者:太空狗 更新时间:2023-10-29 12:27:47 28 4
gpt4 key购买 nike

我有一个 div 在另一个之上。顶部的 div 有 margin-bottom: 10px,底部的 div 有 margin-top: 10px,但两个 div 之间只有 10px 的空间。

实例:http://jsbin.com/efugok/1/edit

带有 Css 的 HTML:

<div style="margin-bottom:10px; background: #e6e6e6;" id="one">one</div>
<div style="margin-top:10px; background: #ccc" id="two">two</div>

渲染:

enter image description here

最佳答案

这就是所谓的 margin 崩溃。这是一种符合规范的行为。 <强> Read more about it.

基本上,当 2 个垂直边距重叠时,只考虑最大的一个。给任何元素留出 20px 的边距来修复它。

关于css - div 在另一个有 margin top 的 div 之上有 margin bottom,只有 1 margin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12921105/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com