HTML Element Style How to - Hover to change color








Question

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

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.myClass2, .myClass1 {<!-- www. jav a  2s .c om-->
  color: red;
}

.myClass2:hover, :hover.myClass1 {
  color: black;
}

.myClass, .myClass1 {
  font-weight: bold;
}
</style>
</head>
<body>
  <p class="myClass2 myClass">java2s.com</p>
  <p class="myClass1">java2s.com</p>
</body>
</html>

The code above is rendered as follows: