HTML Element Style How to - Hover anchor in td change td background image








Question

We would like to know how to hover anchor in td change td background image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
td a {<!--from  w ww .  jav  a 2 s . com-->
  width: 100%;
  height: 100%;
  display: block;
  background: #cce;
}

td a:hover {
  background: #ecc;
}
</style>
</head>
<body>
  <table border="1">
    <tr>
      <td>row 1, cell 1</td>
      <td>row 1, cell 2</td>
    </tr>
    <tr>
      <td>row 2, cell 1</td>
      <td><a href="#">Link</a></td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: