示例工程 12-stacking-context
12-stacking-context/demo-02-trapped/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: 280px;
margin-top: 14px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #ffffff;
}
.parent {
position: absolute;
width: 220px;
height: 160px;
padding: 14px;
border-radius: 12px;
color: #ffffff;
}
.left {
top: 40px;
left: 40px;
background: #2563eb;
z-index: 1;
}
.right {
top: 90px;
left: 160px;
background: #7c3aed;
z-index: 2;
}
.child {
position: relative;
padding: 8px;
border-radius: 8px;
background: #0f172a;
font-family: ui-monospace, monospace;
font-size: 12px;
}
.left .child { z-index: 999; }
.right .child { z-index: 1; }