Visibility and z-index

 <!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Visibility and z-index</title>
    <style>
        .box{
            width: 170px;
            height: 170px;
            border: 2px solid black;
        }
        #box-1{ 
            position: relative;
            top: 49px;
            z-index: -35;
            background-color: green;        }
        #box-2{  
            position: relative;
            top: 14px;
            /* z-index  will work only for position: relative, absolute, fixed or sticky; */
            z-index: -165;
            /* will hide the element and the space */
            /* display: none;  */
            /* will hide the element but will show its empty space */
            /* visibility:hidden;  */
            background-color: red;        
            }
        #box-3{  
            background-color: blue;        }
        #box-4{ background-color: yellow;        }
    </style>
</head>
<body>
    <div class="box" id="box-1"></div>
    <div class="box" id="box-2"></div>
    <div class="box" id="box-3"></div>
    <div class="box" id="box-4"></div>
</body>
</html>

Comments

Popular posts from this blog