Beruflich Dokumente
Kultur Dokumente
CSS3 Selectors
Selector
Type of selector
Description
Universal selector
Type selector
A, B
Grouped selectors
A B
Descendant selector
A>B
Child selector
A+B
A~B
Class selector
#idname
A#idname
ID selector
Attribute selectors
A[att]
Matches any element A that has the given attribute defined, whatever its value.
table[border] {background: white;}
A[att="val"]
Matches any element A that has the specified attribute set to the
specified value.
table[border="3"] {background: yellow;}
583
Selector
Type of selector
Description
A[att~="val"]
Matches any element A that has the specified value as one of the
values in a list given to the specified attribute.
table[class~="example"] {background: yellow;}
A[att|="val"]
A[att^="val"]
Matches any element A that has the specified attribute and its
value begins with the provided string.
img[src^="/images/icons"] {border: 3px solid;}
A[att$="val"]
Matches any element A that has the specified attribute and its
value ends with the provided string.
A[att*="val"]
Matches any element A that has the specified attribute and its
value contains the provided string.
Pseudo-class selectors
a:link
Specifies a style for links that have not yet been visited.
a:link {color: maroon;}
a:visited
:active
Selects any element that has been activated by the user, such as a
link as it is being clicked.
:focus
Selects any element that currently has the input focus, such as a
selected form input.
:hover
Specifies a style for elements (typically links) that appear when the
mouse is placed over them.
a:hover {text-decoration: underline;}
h1:target {color: red;}
:target
:lang(xx)
Pseudo-class selector
:root
:nth-child()
Selects an element that is the nth child of its parent. The notation can include a number, a notation, or the keywords odd or
even.
tr:nth-child(odd) { background: #DDD;}
:nth-last-child()
Selects an element that is the nth child of its parent, counting from
the last one.
li:nth-last-child(2) { color: green;}
584
Appendix B
Selector
Type of selector
Description
:nth-of-type()
:nth-last-oftype()
Selects the nth element of its type, counting from the last one.
:first-child
:last-child
:first-of-type
:last-of-type
:only-child
:only-of-type
:empty
:enabled
UI pseudo-class selector
:disabled
UI pseudo-class selector
:checked
UI pseudo-class selector
:not(X)
Pseudo-element selectors
:first-letter
(::first-letter
Pseudo-element selector
in CSS3)
:first-line
(::first-line in
Pseudo-element selector
CSS3)
:before
(::before in
Pseudo-element selector
CSS3)
:after
(::after in CSS3)
Pseudo-element selector
CSS3 Selectors
585