Friday, March 11, 2016

CSS Selectors Level 3

1. Selector Syntax

Selector

A selector is one or more sequences of simple selectors separated by combinators, an optional pseudo-element may follow the last sequence of simple selectors

selector = sequenceOfSimpleSelectors [combinator1 sequenceOfSimpleSelectors1 ... ] [::pseudoElement]

A sequence of simple selectors

  • it is a chain of simple selectors that are not separated by a combinator
  • it always begins with a type selector or a universal selector. No other type selector or universal selector is allowed in the sequence
  • simple selectors are: type selector, universal selector, attribute selector, class selector, ID selector, pseudo-class.
  • combinators are: whitespace, > "greater-than sign", + "plus sign", ~ "tilde"

The subjects of a selector are the elements of a document tree that are represented by the selector.

1.2 Group of Selectors

A comma-separated list of selectors represents all elements selected by each selector in the list. In CSS, if several selectors share the same declarations, they may be grouped into a comma-separated list.

Example: three CSS rules are condensed into one

h1 { font-family: sans-serif }
h2 { font-family: sans-serif }
h3 { font-family: sans-serif }
is equivalent to:

h1, h2, h3 { font-family: sans-serif }