HTML Element Style How to - Show image colored on hover








Question

We would like to know how to show image colored on hover.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--from   www . j a  v  a  2s.co  m-->
  background-color: red;
  width: 500px;
  height: 500px;
  background-image:url(http://www.java2s.com/style/download.png);
}

div:hover {
  -webkit-filter: grayscale(100%);
}
</style>
</head>
<body>
  <div></div>
</body>
</html>

The code above is rendered as follows: