Animation How to - Create CSS3 animation on width








Question

We would like to know how to create CSS3 animation on width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#demo {<!--  w w  w .j  a  va  2 s.c  om-->
  width: 100px;
  height: 100px;
  background: red;
  transition: width 1s;
  -moz-transition: width 1s; /* Firefox 4 */
  -webkit-transition: width 1s; /* Safari and Chrome */
  -o-transition: width 1s; /* Opera */
}

#demo:hover {
  width: 300px;
}
</style>
</head>
<body>
  <div id="demo"></div>
</body>
</html>

The code above is rendered as follows: