Page Widget How to - Hover to change background








Question

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

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.ninja {<!--  w  w  w  . j a v a 2s . co  m-->
  display: block;
  height: 297px;
  width: 227px;
  background: 0 0 no-repeat url('http://placehold.it/300x300');
}

.ninja:hover {
  background-position: -227px 0;
}
</style>
</head>
<body>
  <div class="ninja"></div>
</body>
</html>

The code above is rendered as follows: