Chapter
1
Selectors
CSSrulesarematchedtoelementswithselectors.Thereareanumberofwaysto
dothis,andyou’reprobablyfamiliarwithmostofthem.Elementtype,classname,
ID,andattributeselectorsareallwell-supportedandwidelyused.
TheSelectorsLevel 31 andLevel 42 specificationsintroducedseveralnewselectors.
Insomecases,thesearenewvariationsofexistingtypes.Inothercases,theyare
newfeaturesofthelanguage.
Inthischapter,we’lllookatthecurrentbrowserlandscapeforCSSselectors,with
afocusonnewerselectors.Thisincludesnewattributeselectorsandcombinators,
andarangeofnewpseudo-classes.InthesectionChoosingSelectorsWisely,we
lookattheconceptofspecificity.
This chapter stops short of being a comprehensive look at all selectors―that could
be a book unto itself. Instead, we’ll focus on selectors with good browser support
that are likely to be useful in your current work. Some material may be old hat, but
it’s included for context.
(^1) http://dev.w3.org/csswg/selectors-3/
(^2) http://dev.w3.org/csswg/selectors-4/