HTML Element Style How to - Style Inner span with hover








Question

We would like to know how to style Inner span with hover.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
a:hover {<!--from w  w w .j  a v a  2s . co m-->
  font-weight: bold;
}

a:hover .bar {
  font-weight: normal;
}
</style>
</head>
<body>
  <a href="#">
    <div class="foo">
      hello <span class="bar">world</span>
    </div>
  </a>
</body>
</html>

The code above is rendered as follows: