Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Animate CSS z-index property

With CSS, how can perform animation on z-index property?



1 Answer
George John

To implement animation on z-index property with CSS, you can try to run the following code

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            position: absolute;
         }
         #box div {
            background-color: orange;
            border: 2px solid yellow;
            width: 100px;
            height: 100px;
            opacity: 0.3;
         }
         div#demo {
            opacity: 1;
            background-color: coral;
            z-index: 1;
            animation: myanim 3s;
         }
         @keyframes myanim {
            30% {
               z-index: 3;
            }
         }
      </style>
   </head>
   <body>
      <h1>CSS z-index property</h1>
      <div id = "box">
         <div id = "demo"></div>
         <div style = "top:20px;left:20px;z-index:1;">One</div>
         <div style = "top:40px;left:40px;z-index:2;">Two</div>
         <div style = "top:60px;left:60px;z-index:3;">Three</div>
         <div style = "top:80px;left:80px;z-index:4;">Four</div>
         <div style = "top:100px;left:40px;z-index:5;">Five</div>
         <div style = "top:120px;left:60px;z-index:6;">Six</div>
         <div style = "top:140px;left:80px;z-index:7;">Seven</div>
      </div>
   </body>
</html>
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.