5.6: Z-index
The property z-index is used to assign positional layers to stacked or overlapping elements
default value is zero(0)
lower number = lower in the stack
<div class="wrapper">
<figure class="box-1"></figure>
<figure class="box-2"></figure>
<figure class="box-3"></figure>
<figure class="box-4"></figure>
<figure class="box-5"></figure>
<figure class="box-6"></figure>
<figure class="box-7"></figure>
</div>
body {
background: #eee;
}
.wrapper {
position: absolute;
background: white;
width: 600px;
height: 600px;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -300px;
-webkit-box-shadow: 0px 40px 60px -20px rgba(0, 0, 0, 0.2);
box-shadow: 0px 40px 60px -20px rgba(0, 0, 0, 0.2);
}
.box-1 {
position: absolute;
width: 400px;
height: 400px;
background: rgba(199,21,133,1.0);
top: 50%;
left: 50%;
margin-top: -200px;
margin-left: -200px;
}
.box-2 {
position: absolute;
width: 200px;
height: 200px;
background: pink;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
}
.box-3 {
position: absolute;
width: 180px;
height: 180px;
background:rgba(199,21,133,1.0)rgba(199,21,133,1.0);
top: 50%;
left: 50%;
margin-top: -90px;
margin-left: -90px;
}
.box-4 {
position: absolute;
width: 160px;
height: 160px;
background: white;
top: 50%;
left: 50%;
margin-top: -80px;
margin-left: -80px;
}
.box-5 {
position: absolute;
width: 140px;
height: 140px;
background: rgba(199,21,133,1.0);
top: 50%;
left: 50%;
margin-top: -70px;
margin-left: -70px;
z-index: 20;
}
.box-6 {
position: absolute;
width: 120px;
height: 120px;
background: rgba(72,61,139,1.0);
top: 50%;
left: 50%;
margin-top: -160px;
margin-left: -160px;
z-index: 50;
}
.box-7 {
position: absolute;
width: 100px;
height: 100px;
background: rgba(106,90,205,1.0);
top: 50%;
left: 50%;
margin-top: -90px;
margin-left: -90px;
z-index: 100;
}
Last updated