Animation How to - Hover to do CSS3 Alpha Transition on Image








Question

We would like to know how to hover to do CSS3 Alpha Transition on Image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!-- w w  w .ja  va  2  s .com-->
  margin: 20px;
  padding: 0;
}

.box {
  position: absolute;
  background:
    url("http://www.java2s.com/style/download.png");
  color: #fff;
  font-size: 1.4em;
  font-weight: bold;
  min-height: 300px;
  min-width: 300px;
  padding: 10px;
  text-align: center;
  -webkit-transition-property: height, background, color;
  -webkit-transition-duration: 1s, 1s, 0.5s;
  -webkit-transition-timing-function: linear, ease-in, linear;
  -webkit-border-radius: 1em;
}

#box2 {
  background:
    url("http://java2s.com/style/demo/Google-Chrome.png");
  -webkit-transition: opacity .5s ease-in;
  -moz-transition: opacity .5s ease-in;
  -o-transition: opacity .5s ease-in;
  transition: opacity .5s ease-in;
}

#box2:hover {
  opacity: 0;
  color: #000;
  height: 150px;
}
</style>
</head>
<body>
  <div id="box" class="box"></div>
  <div id="box2" class="box"></div>
</body>
</html>

The code above is rendered as follows: