You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute, fixed, or relative).
Let's try out the following example to understand how it basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Overlaying One DIV over Another DIV</title>
<style>
.container{
width: 200px;
height: 200px;
position: relative;
margin: 20px;
}
.box{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0.8; /* for demo purpose */
}
.stack-top{
z-index: 9;
margin: 20px; /* for demo purpose */
}
</style>
</head>
<body>
<div class="container">
<div class="box" style="background: red;"></div>
<div class="box stack-top" style="background: blue;"></div>
</div>
</body>
</html>
In the example above, the div element with the class .stack-top will be on top of another div.
Use the CSS
z-indexPropertyYou can use the CSS
positionproperty in combination with thez-indexproperty to overlay an individualdivover anotherdivelement. Thez-indexproperty determines the stacking order for positioned elements (i.e. elements whose position value is one ofabsolute,fixed, orrelative).Let's try out the following example to understand how it basically works:
In the example above, the
need an explanation for this answer? contact us directly to get an explanation for this answerdivelement with the class.stack-topwill be on top of anotherdiv.