Page Widget How to - Hover to change background image








Question

We would like to know how to hover to change background image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.picture {<!--from   w  ww . j  av a 2 s.c o m-->
  background: url(http://http://www.java2s.com/style/download.png) no-repeat;
  background-size: 190px;
  width: 190px;
  height: 190px;
  border: 1px solid black;
}

.picture:hover {
  background:url(http://placehold.it/200x200) no-repeat;
  background-size: 190px;
}
</style>
</head>
<body>
  <div class="picture" />
</body>
</html>

The code above is rendered as follows: