Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (55 sloc) 3.89 KB
For details visit http://www.w3.org/TR/css3-selectors/
Selector Meaning   CSS Spec
 
* any element   2
E an element of type E   1
E[foo] an element with attribute 'foo'   2
E[foo=bar] an element with attribute 'foo', value is exactly equal to 'bar'   2
E[foo="bar"] an element with attribute 'foo', value is exactly equal to 'bar'   2
E[foo~="bar"] an element whose 'foo' attribute contains the word 'bar'   2
E[foo^="bar"] an element whose 'foo' attribute starts with 'bar'   3
E[foo$="bar"] an element whose 'foo' attribute ends with 'bar'   3
E[foo*="bar"] an element whose 'foo' attribute contains the substring 'bar'   3
E:root root of the document 3
E:nth-child(n) an E element, n-th child of its parent 3
E:nth-last-child(n)
E:nth-of-type(n)
E:nth-last-of-type(n)
E:first-child an E element, who is the first child of its parent
E:last-child an E element, who is the last child of its parent
E:first-of-type an E element, who is the first child of its type
E:last-of-type an E element, who is the first last of its type
E:only-child an E element, who is the only child of its parent
E:only-of-type an E element, who is the only child of its type
E:empty an E element, with no children (including text nodes)
E:link a hyperlink which has not yet being :visited
E:visited a hyperlink which has been visited
E:active an E element when undergoing certain user actions
E:hover an E element when being hovered
E:focus an E element which is currently the focus
E:target
E:enabled an E element with attribute enabled=enabled
E:disabled an E element with attribute disabled=disabled
E:checked an E element with attribute checked=checked
E::first-line an E element's first line of text
E::first-letter an E element's first letter of text
E::before generated content before an E element
E::after generated content after an E element
E.someclass an E element with the given class. same as E[class~=someclass]
E#someid an E element with the given id. same as E[id=someid]
E:not(selector) an E element matching the negated selector
E F an F element which is a descendant of E
E > F an F element which is a direct child to E
E + F an F element immediately preceded by an E element
E ~ F an F element preceded by an E element
Examples
ul li * all elements within a ul's li
ul ul li all li's who are descendants of 2 or more ul's
ul li:first-child first li
ul li:nth-child(even) all even li's (2, 4, 6, ...)
ul li:nth-child(2n) all even li's (2, 4, 6, ...)
ul li:nth-child(odd) all odd li's (1, 3, 5, ...)
ul li:nth-child(2n+1) all odd li's (1, 3, 5, ...)
input[type=button]:not([disabled]) all buttons which are not disabled
input + span.description all spans with the .description class immediately following an input element
input ~ span.description all spans with the .description class following an input element