HTML and CSS Reference
In-Depth Information
Selector
Description
Example
Defined In
:nth-of-type( n ) Selects the element
that is the nth child of
its parent that is its
type
CSS3
strong:nth-of-type(5) {text-
decoration: underline;}
/* underlines the fifth strong tag
under a parent */
:only-child
Selects an element if
it's the only child of its
parent
h1:only-child {color: blue;}
/* sets the h1 color to blue if
the h1 is the only child of its
parent */
CSS3
Selects an element if
it's the only child of its
parent with its type
:only-of-type
p:only-of-type {font-weight: bold;}
/*sets the p element to be bold if
it is the only p tag child of its
parent */
CSS3
:root
Selects the element
that is the root of the
document
:root {background-color: blue;}
/* sets the background color to
blue for the root element */
CSS3
::selection
Selects the part of
the element that is
currently selected;
supported in Firefox as
::-moz-selection
as well
#test::selection {color: red;}
/* makes the text red when
selected */
CSS3
:target
Selects the element
that is the target of a
referring URI
:target{color:red;}
/* if the element is the target of
the referring URI, the color is
set to red */
CSS3
T ABLE 5-5 CSS Selectors (continued)
N OTE Most of the CSS3 selectors are not supported in Internet Explorer browsers, including
version 8.0, though they are widely supported by other browser vendors.
Page Media Selectors
CSS2 and beyond provide special support for multiple media types. Print styles in
particular introduce interesting selectors that are specific for page media. Table 5-6
summarizes the selectors used for such media-dependent styles.
N OTE CSS properties like orphans , page-break-after , page-break-before ,
page-break-inside , and widows are often used in conjunction with these selectors.
See the corresponding section in this chapter for the particular property for more information.
 
Search WWH ::




Custom Search