stacking context e6
by Boyanliuu
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>stacking context</title>
</head>
<body>
<div class="parent">
parent
<div class="child1">child1</div>
<div class="child2">
child2
<div class="child2-1">child2-1</div>
<div class="child2-2">child2-2</div>
</div>
</div>
</body>
</html>
CSS
* {
margin: 0;
padding: 0;
}
.parent {
width: 100px;
height: 200px;
background: #168bf5;
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
.child1 {
width: 100px;
height: 200px;
background: #32d19c;
position: absolute;
top: 20px;
left: 20px;
z-index: 1;
}
.child2 {
width: 100px;
height: 200px;
background: black;
position: absolute;
top: 40px;
left: 40px;
z-index: -1;
}
.child2-1 {
width: 100px;
height: 200px;
background: #e45050;
position: absolute;
top: 60px;
left: 60px;
z-index: 9999;
}
.child2-2 {
width: 100px;
height: 200px;
background: #db68a7;
position: absolute;
top: 80px;
left: 40px;
z-index: -9999;
}