, asked
Views : 3

CSS top property with Animation

With CSS, how can I perform animation on the top property?

The following is my div

div {
   position: absolute;
   width: 300px; 
   height: 200px;
   background-color: orange;
   color: white;
   top: 0;
}

1 Answer
Chandu yadav

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

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            position: absolute;
            width: 300px;
            height: 200px;
            background-color: orange;
            color: white;
            top: 0;
            animation: myanim 3s infinite;
         }
         @keyframes myanim {
            30% {
               top: 300px;
            }
         }
      </style>
   </head>
   <body>
      <h1>CSS top property</h1>
      <div>
         <h1>This is demo text!</h1>
      </div>
   </body>
</html>

Advertisements
Related Questions