Animation How to - Slide text and mask up for image








Question

We would like to know how to slide text and mask up for image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
p {<!--from w  ww.  j ava  2 s.  c  o m-->
  width: 200px;
  height: 200px;
  overflow: hidden;
  position: relative;
}

p span {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 100px;
  display: block;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  text-align: center;
  line-height: 100px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7em;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}

a {
  text-decoration: none;
}

p a:hover span {
  top: -100px;
}
</style>
</head>
<body>
  <p>
    <a href="#"> 
       <img src="http://placehold.it/200x100"
      width="200" height="100"> 
      <span>OK</span>
    </a>
  </p>
</body>
</html>

The code above is rendered as follows: