HTML Element Style How to - Change background color after clicking anchor using target pseodo class








Question

We would like to know how to change background color after clicking anchor using target pseodo class.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
a:target {<!--  w  w  w. j  a  v  a 2s.  c o m-->
  transition: background-color 1s ease-in;
  -webkit-transition: background-color 1s ease-in;
  -moz-transition: background-color 1s ease-in;
  background-color: yellow;
}
</style>
</head>
<body>
  <a href="#" id="see">See</a>
  <a href="#" id="works">works</a>
  <a href="#" id="well">well</a>
</body>
</html>

The code above is rendered as follows: