0

My HTML file:

 * {
        margin: 0;
    }
    .box {
        width: 0px;
        height: 0%;
        background: green;
        border: 1px solid black;
        animation-name: grow;
        animation-duration: 2s;
    }
    
    @keyframes grow {
        from {width: 0px; height: 0%; background: red;}
        to {width: 340px; height: 100%; background: green;}
    }
<div class="box"></div>
   

The idea is that my HTML file will have a side bar on the left side of the window that stretches from the left at the beginning. And it should stay that way, I mean, the "div".class should stay after stretching, not disappear.

1 Answers1

1

Add position: absolute; to .box. Your animation does not work because body is 0 height.

* {
        margin: 0;
    }
    .box {
        width: 0px;
        height: 0%;
        background: green;
        border: 1px solid black;
        animation-name: grow;
        animation-duration: 2s;
        position: absolute;
    }
    
    @keyframes grow {
        from {width: 0px; height: 0%; background: red;}
        to {width: 340px; height: 100%; background: green;}
    }
<div class="box"></div>
Chiara Ani
  • 918
  • 7
  • 25