示例工程 08-box-model
08-box-model/demo-02-margin-collapse/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>外边距折叠</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>外边距折叠</h1>
<section>
<h2>普通块级:外边距折叠</h2>
<div class="collapse">
<p>第一段,margin-bottom: 30px。</p>
<p>第二段,margin-top: 20px;间距不是 50px。</p>
</div>
</section>
<section>
<h2>flex + gap:不会折叠</h2>
<div class="flex">
<p>第一项。</p>
<p>第二项;间距由 gap 控制。</p>
</div>
</section>
</body>
</html>