CSS 2.1 selectors


Overview of CSS 2.1 selector syntax
Selector type Pattern Description
Universal * Matches any element.
Type E Matches any E element.
Class .info Matches any element whose class attribute contains the value info.
ID #footer Matches any element with an id equal to footer.
Descendant E F Matches any F element that is a descendant of an E element.
Child E > F Matches any F element that is a child of an E element.
Adjacent E + F Matches any F element immediately preceded by a sibling element E.
Attribute E[att] Matches any E element that has an att attribute, regardless of its value.
Attribute E[att=val] Matches any E element whose att attribute value is exactly equal to val.
Attribute E[att~=val] Matches any E element whose att attribute value is a list of space-separated values, one of which is exactly equal to val.
Attribute E[att|=val] Matches any E element whose att attribute has a hyphen-separated list of values beginning with val.
The :first-child pseudo-class E:first-child Matches element E when E is the first child of its parent.
The link pseudo-classes E:link
E:visited
Matches not yet visited (:link) or already visited (:visited) links.
The dynamic pseudo-classes E:active
E:hover
E:focus
Matches E during certain user actions.
The :language pseudo-class E:lang(c) Matches elements of type E that are in language c.
The :first-line pseudo-element E:first-line Matches the contents of the first formatted line of element E.
The :first-letter pseudo-element E:first-letter Matches the first letter of element E.
The :before and :after pseudo-elements E:before
E:after
Used to insert generated content before or after an element’s content.








descendant
An element that is the child, grandchild or later descendant of an element in the document tree.
ancestor
An element that is the parent, grandparent or earlier ancestor of an element in the document tree.
child
The direct descendant of an element. No other elements may come between the two in the document tree.
parent
The direct ancestor of an element. No other element may come between the two in the document tree.
sibling
An element that has the same parent as the current element.

Комментарии