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








Question

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

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.main-banner a#link1 {<!-- w ww.  j  av  a 2 s. c  o m-->
  background: red;
  display: block;
  width: 310px;
  height: 85px;
  top: 190.2px;
  left: 277px;
}

.main-banner a#link1:hover {
  background: green;
}
</style>
</head>
<body>
  <div class="main-banner">
    <a href="#" id="link1">d</a>
  </div>
</body>
</html>

The code above is rendered as follows: