Hi dear welcome to Ascode Blog . In this post we are going to learn to CSS Z-index property. First Creat A index.html file Copy This HTML CODE and pest it one your code editor. 2ndly creat style.css file Then Copy The CSS CODE and pest it then open the index.html file with your browser.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>z-index css</title>
</head>
<body>
<div class="bg1"></div>
<div class="bg2"></div>
</body>
</html>
CSS
body{
position: relative;
display: flex;
justify-content: center;
min-height: 100vh;
align-items: center;
}
.bg1 {
background: red;
width: 300px;
height: 300px;
border-radius: 5px;
/* change z-index value you will see diffrence */
z-index: 1;
}
.bg2 {
background: blue;
width: 300px;
height: 300px;
border-radius: 5px;
transform: translateX(-100%);
/* change z-index value you will see diffrence */
z-index: 2;
}
0 Comments