:target Selector
A fragment identifier can be added to a URL to navigate directly to an element based its id attribute. For example, example.html#myelement goes to the element whose id is 'myelement' in example.html.
:target selector matches the element that the URL fragment identifier refers to.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style type="text/css">
:target {
border: thin black solid;
padding: 4px;
color:red;
}
</style>
</head>
<body>
<a href="http://java2s.com">Visit the java2s.com</a>
<p id="mytarget">HTML and CSS</p>
</body>
</html>
If you save the above document as example.htm. You can see the result of target selector by referencing example.htm with example.htm#mytarget.
Home
HTML CSS Book
CSS
HTML CSS Book
CSS
Pseudo Selectors:
- ::first-line Selector
- ::first-letter Selector
- :before Selector
- :after Selector
- CSS Counter Feature
- :root Selector
- Child Selectors
- :first-child Selector
- :last-child Selector
- :only-child Selector
- :only-of-type selector
- :nth-child(n)
- :nth-last-child(n)
- :nth-of-type(n)
- :nth-last-of-type(n)
- Enabled Elements with :enabled
- Disabled Elements with :disabled
- Checked Elements with :check
- Default Elements with :default
- Valid Elements with :valid
- Invalid input Elements with :invalid
- :in-range selector
- :out-of-range selector
- :required selector
- :optional selector
- :link selector matches hyperlinks.
- :visited selector matches visited hyperlinks.
- :hover Selector
- :active Selector
- :focus Selector
- Negation Selector not
- :empty Selector
- :lang Selector
- :target Selector
Related: