The HTML Workshop

CSS Selectors

Universal Selector

* {background-color:#acf;}

Type Selector

h1 {background-color:#acf;}

Class Selector

.someclassname {background-color:#acf;}
p.someclassname {background-color:#acf;}

ID Selector

#someidname {background-color:#acf;}
p#someidname {background-color:#acf;}

Descendant Selector

h1 span {background-color:#acf;}

Child Selector (match any of the second element that are children of the first)

blockquote > span {background-color:#acf;}

Adjacent Selector (match any of the second element immediately preceding the first (sibling))

p + hr {background-color:#acf;}

Attribute Selector (match any of this element with this attribute)

input[disabled]

Attribute Selector (match any of this element with this attribute of this value)

input[type=submit]
input[type=submit][type=reset] (using multiple)

Attribute Selector (match any of this element with this attribute with this value within a list of space-separated values)

td[headers~=col1]

Attribute Selector (match any of this element with this attribute of this value as the first among a hyphen-separated list)

p[lang|=en]

:first-child Pseudo-class Selector (matches any of this element that is the first child of its parent)

li:first-child

Link and Dynamic Pseudo-class Selector

a:link {color:#acf;}
a:visited {color:#acf;}
a:active {color:#acf;}
a:hover {color:#acf;}

:language Pseudo-class Selector (matches any of this element that are in language ccccc)

p:lang(sv) { quotes: "\201D" "\201D" "\2019" "\2019"; }

:first-line Pseudo-element Selector (matches content of first formatted line of this kind of element)

p:first-line

:first-letter Pseudo-element Selector (matches content of the first letter of this kind of element)

p:first-letter

:before and :after Pseudo-element (used to insert generated content before or after this kind of element's content)

p:before {content:""; display:block; height:20px; width:20px;}
p:after {content: " (" attr(href) ") ";}
 
© 1999-2009. HTML Workshop. GordeonBleu. Gordon Mei. XHTML 1.1 | CSS 2.1.