示例工程 12-stacking-context
12-stacking-context/app/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>
<header class="site-header">
<span class="brand">STACK MAG</span>
<nav aria-label="页面导航">
<a href="#cover">封面</a>
<a href="#layers">层次</a>
<a href="#notes">笔记</a>
</nav>
</header>
<main class="page">
<section class="cover" id="cover">
<div class="cover-bg" aria-hidden="true"></div>
<div class="cover-card">
<p class="issue">ISSUE 12 / STACKING</p>
<h1>层叠上下文</h1>
<p class="dek">为什么 z-index: 9999 也不一定在最上面?</p>
<p class="byline">层叠、上下文与杂志封面的一次练习</p>
</div>
<span class="cover-badge">NEW</span>
</section>
<section class="panel" id="layers">
<h2>三个盒子,谁在上面?</h2>
<p>三个绝对定位盒子重叠;z-index 只在同一层叠上下文内比较。</p>
<div class="stack-demo">
<div class="layer layer-a">A z-index: 1</div>
<div class="layer layer-b">B z-index: 3</div>
<div class="layer layer-c">C z-index: 2</div>
</div>
</section>
<section class="panel" id="notes">
<h2>本期笔记</h2>
<div class="note-grid">
<article class="note">
<h3>上下文</h3>
<p>z-index、opacity、transform 都可能创建新的层叠上下文。</p>
</article>
<article class="note">
<h3>子级被隔离</h3>
<p>子级的 z-index 再大,也只在父级上下文内比较。</p>
</article>
<article class="note">
<h3>顶层</h3>
<p>dialog、popover 进入 top layer,不受普通 z-index 影响。</p>
</article>
</div>
</section>
</main>
<footer class="site-footer">示例数据,仅用于教程演示。</footer>
</body>
</html>