HTML Element Style How to - Hover to change div element color








Question

We would like to know how to hover to change div element color.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#SecondLink {<!--from  w  w w .j  a  va  2 s . c  o m-->
  background-color: red;
  width: 100px;
  height: 100px
}

#SecondLink:hover {
  background-color: green;
}
</style>
</head>
<body>
  <a href="#SecondLink"><div id="SecondLink"></div></a>
</body>
</html>

The code above is rendered as follows: