示例工程 12-stacking-context
12-stacking-context/demo-01-z-index/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
body {
margin: 0;
padding: 32px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, sans-serif;
line-height: 1.7;
}
h1 {
margin: 0 0 8px;
font-size: 26px;
}
.stage {
position: relative;
height: 240px;
margin-top: 14px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #ffffff;
}
.box {
position: absolute;
width: 180px;
height: 110px;
padding: 12px;
border-radius: 10px;
color: #ffffff;
font-family: ui-monospace, monospace;
font-size: 13px;
}
.a { top: 30px; left: 30px; background: #2563eb; z-index: 1; }
.b { top: 70px; left: 110px; background: #7c3aed; z-index: 3; }
.c { top: 110px; left: 190px; background: #db2777; z-index: 2; }