Example
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display: flex elements).
<html>
<head>
<style>
.container {
position: relative;
}
.black-box {
position: relative;
z-index: 1;
border: 2px solid black;
height: 100px;
margin: 30px;
}
.gray-box {
position: absolute;
z-index: 3;
background: lightgray;
height: 60px;
width: 70%;
left: 50px;
top: 50px;
}
.green-box {
position: absolute;
z-index: 2;
background: lightgreen;
width: 35%;
left: 270px;
top: -15px;
height: 100px;
}
</style>
</head>
<body>
<div class="container">
<div class="black-box">Black box</div>
<div class="gray-box">Gray box</div>
<div class="green-box">Green box</div>
</div>
</body>
</html>
<html>
<head>
<style>
.container {
position: relative;
}
.black-box {
position: relative;
border: 2px solid black;
height: 100px;
margin: 30px;
}
.gray-box {
position: absolute;
background: lightgray;
height: 60px;
width: 70%;
left: 50px;
top: 50px;
}
.green-box {
position: absolute;
background: lightgreen;
width: 35%;
left: 270px;
top: -15px;
height: 100px;
}
</style>
</head>
<body>
<div class="container">
<div class="black-box">Black box</div>
<div class="gray-box">Gray box</div>
<div class="green-box">Green box</div>
</div>
</body>
</html>
_____ {
position: absolute;
top: 0;
_____ : 1;
}
_____ {
position: absolute;
top: 0;
_____ : 0;
}
</style>
<body>
<h1 id="mytitle">This is a heading</h1>
<p id="myintro">This is a paragraph</p>
</body>
<style>
#mytitle {
position: absolute;
top: 0;
z-index: 1;
}
#myintro {
position: absolute;
top: 0;
z-index : 0;
}
</style>
<body>
<h1 id="mytitle">This is a heading</h1>
<p id="myintro">This is a paragraph</p>
</body>
10 videos|41 docs|23 tests
|
|
Explore Courses for Class 6 exam
|