Using the :target Selector

Description

The :target selector matches the element that the URL fragment identifier refers to.

Example

The following code shows the :target selector in action.


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
:target {<!--from   ww  w . j  a  v  a2 s  .c  om-->
  border: thin black solid;
  padding: 4px;
  color: red;
}
</style>
</head>
<body>
  <a href="http://java2s.com">Visit the website</a>
  <p id="mytarget">
    I like <span>HTML</span> and CSS.
  </p>
  <a id="w3clink" href="http://w3c.org">Visit the W3C website</a>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table