HTML Element Style How to - Toggle the opacity of LI Elements








Question

We would like to know how to toggle the opacity of LI Elements.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
ul:hover li {<!--  w ww  . ja  v  a  2 s.  co m-->
  opacity: 0.5;
}

ul li:hover {
  opacity: 1;
}
</style>
</head>
<body>
  <ul>
    <li>A</li>
    <li>B</li>
    <li>C</li>
    <li>D</li>
    <li>E</li>
  </ul>
</body>
</html>

The code above is rendered as follows: