Effect How to - Change div background color on hover








Question

We would like to know how to change div background color on hover.

Answer


<html>
<head>
  <style type="text/css">
  .link-container {<!--from   ww  w  .j  a  v a2  s . c om-->
    border: 1px solid;
    width: 50%;
    height: 20px;
  }

  .link-container a {
    display: block;
    background: #c8c8c8;
    height: 100%;
    text-align: center;
  }

  .link-container a:hover {
    background: #f8f8f8;
  }

  </style>

</head>
<body>

  <div class="link-container">
    <a href="">java2s.com</a>
  </div>

  <div class="link-container">
    <a href="">java2s.com</a>
  </div>

</body> 
</html>

The code above is rendered as follows: