jigga jigga - 6 months ago 12
CSS Question

Can I move an animated line from right to left?

I'm animating line with css3 from width:0 to width:100%. At the moment is moving from left to right, but I want to make it to start from right to left. Is this posible at all with keyframes?

here is my code



.content {
width: 400px;
height: 200px;
color: white;
cursor: pointer;
text-transform: uppercase;
padding-bottom: 20px;
position: relative;
background: #333;
}
.content .line {
height: 2px;
background: white;
position: absolute;
top: 10px;
-webkit-animation: dude .75s 1 forwards;
-moz-animation: dude .75s 1 forwards;
-o-animation: dude .75s 1 forwards;
animation: dude .75s 1 forwards;
}
@-webkit-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
@-moz-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
@-o-keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}
@keyframes dude {
0% {
width: 0;
}
100% {
width: 100%;
}
}

<div class="content">
<div class="line"></div>
</div>




Answer

See this FIDDLE

add

.content .line {
   right: 0;
}

.content {
  width: 400px;
  height: 200px;
  color: white;
  cursor: pointer;
  text-transform: uppercase;
  padding-bottom: 20px;
  position: relative;
  background: #333;
}
.content .line {
  height: 2px;
  background: white;
  position: absolute;
  top: 10px;
  right: 0;
  -webkit-animation: dude .75s 1 forwards;
  -moz-animation: dude .75s 1 forwards;
  -o-animation: dude .75s 1 forwards;
  animation: dude .75s 1 forwards;
}
@-webkit-keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
@-moz-keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
@-o-keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
@keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
<div class="content">
  <div class="line"></div>
</div>

Comments