0

I have created animation using css, below is code for that

.div
{
 position:relative;
 width:250px;
 height:150px;
 background-color:gray;
}
    .div:before {
        content: "";
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100px;
        height: 100px;
        animation-name: drawline;
        animation-duration: 2s;
        -webkit-animation-name: drawline;
        -webkit-animation-duration: 2s;
        border: 1px solid #fff;
    }
@-webkit-keyframes drawline
{
 0%
 {
  width:0px;
 }
 100%
 {
  width:100px;
 }
}
@keyframes drawline
{
 0%
 {
  width:0px;
 }
 100%
 {
  width:100px;
 }
}
<div class="div"></div>

This animation is working on chrome but not working on safari because I have given animation to :before. What should I do? Please help.

vedankita kumbhar
  • 1,468
  • 6
  • 19
  • 42

1 Answers1

0

Try to set your default width: 100px; to width: 0px;. And apparently Safari wasn't happy when starting animation form "0%". You can try something like this :

.div
{
 position:relative;
 width:250px;
 height:150px;
 background-color:gray;
}
    .div:before {
        content: "";
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100px;
        height: 100px;
        animation-name: drawline;
        animation-duration: 2s;
        -webkit-animation-name: drawline;
        -webkit-animation-duration: 2s;
        border: 1px solid #fff;
    }
@-webkit-keyframes drawline
{
 0% {
    opacity: 0; 
    width: 100px;
  }
  1% {
    opacity: 1;
    width: 0;
  }
  100% {
    width: 100px;
  }
}

@keyframes drawline {
  0% {
    opacity: 0; 
    width: 100px;
  }
  1% {
    opacity: 1;
    width: 0;
  }
  100% {
    width: 100px;
  }
}
<div class="div"></div>
j-printemps
  • 1,288
  • 11
  • 21