Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS animate width from 0px to inline css defined % value

Is there a way with pure CSS without javascript to animate element's width to server generated value? Let's say I have this div:

<div class="bar" style="width:{$value}%;"></div>

I would like it to animate from 0 to $value that is set by PHP on page render. So initial state forced by animation would be width: 0px and the final would be width: {$value}%;

like image 996
simPod Avatar asked Feb 21 '26 18:02

simPod


1 Answers

A working solution using animation:

JSFiddle Demo

<div class="bar" style="width:80%;"></div> <!-- where 80% is the PHP value-->

.bar{
  background: lime;
  padding: 30px 0;
  animation: test 2s;
}

@keyframes test {
  0% {width: 0;}
}
like image 125
Bian Jiaping Avatar answered Feb 23 '26 07:02

Bian Jiaping