Animation How to - Animate background colour from solid to transparent








Question

We would like to know how to animate background colour from solid to transparent.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#cs4 {<!--from w w  w . ja  va2  s .com-->
  background: #ff6600;
  width: 200px;
  height: 200px;
  -webkit-animation: fadeOut 2s ease-in;
}

@-webkit-keyframes fadeOut {
  from {background: #ff6600;}
    to {background: transparent;}
}
</style>
</head>
<body>
  <div id="cs4"></div>
</body>
</html>

The code above is rendered as follows: