Q:

How to Overlay One DIV Over Another DIV using CSS

0

How to Overlay One DIV Over Another DIV using CSS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the CSS z-index Property

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 absolutefixed, 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

HTML / CSS Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Stretch and Scale an Image in the Backgroun... >>
<< How to Auto-resize an Image to Fit into a DIV Cont...