HTML and CSS Reference
In-Depth Information
Selector
Description
Example
Defined In
:default
Selects the elements
that are the default
among a set of similar
elements
:default {background-color:
red;}
/* sets the background color
of a default button like a
submit to red */
CSS3
:first-child
Selects the element
only if the element is
the first child of its
parent
p:first-child { color: red;}
/* sets the font color to red
for all of the p tags that
are the first child of their
parent */
CSS2
:last-child
Selects the element
that is the last child
of its parent
p:last-child {font-size:
small;}
/* sets the font size to small
on the p tags that are the
last child of their parent */
CSS3
:first-of-type
Selects the element
that is the first child
of its parent that is
of its type
strong:first-of-type
{font-size: bigger;}
/* sets the font size bigger
on the first strong tag of its
parent */
CSS3
Selects the element
that is the last child
of its parent that is of
its type
CSS3
:last-of-type
strong:last-of-type
{font-size: smaller;}
/* sets the font size smaller
on the last strong tag of its
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
CSS3
: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 */
:nth-child(n)
Selects the element
that is the nth child of
its parent
div:nth-child(2)
{background-color: red;}
/* sets the background color
to red if the div is its
parent's second child */
CSS3
T ABLE 4-9 CSS Pseudo-Class Selectors (continued)
 
Search WWH ::




Custom Search