visibility and z-index in CSS
<!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">
<link rel="stylesheet" href="CSS/Visibility_z_index.css">
<title>Visibility and z-index</title>
</head>
<body>
<div class="box" id="box1"></div>
<div class="box" id="box2"></div>
<div class="box" id="box3"></div>
<div class="box" id="box4"></div>
</body>
</html>
Below File is css/Visibility_z_index.css File.
.box {
width: 170px;
height: 170px;
border: 2px solid #000000;
/* display: inline-block; */
}
#box1 {
/* z-index will work only for position: relative, absolute, fixed or sticky (Not for "static") */
position: relative;
top: 49px;
z-index: 35;
background-color: #008000;
}
#box2 {
/* Main Difference between "display:none" and "visibility: hidden" is that
"visibility: hidden" reserve space and "display: none" does not reserve space*/
/* "display: none" will hide the element and the space */
/* display: none; */
/* "visibility: hidden" will hide the element but will show its empty space */
/* visibility: hidden; */
background-color: #ff0000;
position: relative;
top: 14px;
z-index: -1;
}
#box3 {
background-color: #0000ff;
}
#box4 {
background-color: #ffff00;
}
.png)
Comments
Post a Comment