Animation How to - Animate border width








Question

We would like to know how to animate border width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
@-moz-keyframes foo {<!--from   ww  w.  ja v  a  2 s. com-->
   from { border:0 solidb lack;}
   to {  border: 20px solid black;}
}
@-ms-keyframes foo {
   from { border:0 solid black;}
   to {  border: 20px solid black;}
}
@-webkit-keyframes foo {
   from { border:0 solid black;}
   to {  border: 20px solid black;}
}
div {
  width: 50px;
  height: 50px;
  border-style: solid;
  -moz-animation: 1s foo infinite alternate;
  -ms-animation: 1s foo infinite alternate;
  -webkit-animation: 1s foo infinite alternate;
}
</style>
</head>
<body>
  <div></div>
</body>
</html>

The code above is rendered as follows: