HTML Element Style How to - Add hover effect to div








Question

We would like to know how to add hover effect to div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.foo:hover {<!--from   ww  w  .  jav  a  2s.  c o m-->
  color: red;
  display: none;
}
</style>
</head>
<body>
  <div class="foo">text</div>
</body>
</html>

The code above is rendered as follows: