Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

W3C CSS Selectors Reference

Source: http://www.w3schools.com/cssref/css_selectors.asp

Selector Example Example description

Type Sectors h1 { margin: 0; } Selects all <h1> elements


element

Multiple Selectors h2,h3,h4 { color: Selects all <h2> <h3> <h4> elements
element,element green; }

Class .nav {padding: 1em Selects all elements with class="nav"


.class 2em; background:
green;}

Div ID #header {padding: Selects the element with id="header"


#id 2em;color: #fff;
background: #000;}

Universal *{margin: 0; Selects all elements


* padding: 0;}

Descendant .nav ul{margin: 0; Selects all <ul> elements inside <.nav>


element element padding: 0;} elements

.nav li {display: Selects all <li> elements inside <.nav>


inline; margin-right: elements
1em;}
Selects all <a> elements inside <li> and
.nav li a { color: #fff; <.nav> elements
}
Child .nav li > a { text- Selects all <a> elements where the
element>element decoration: none; } parent is a <.nav> and <li> element

adjacent sibling h3 + h4 { margin- Selects all <h4> elements that are


element+element top: 2em; } placed immediately after <h3>

:link a:link { color: green; Selects all unvisited links


}

:visited a:visited { color: Selects all visited links


brown; }

:focus a:focus { color: Selects the anchor element which has


black; } focus

:hover a:hover { color: lime; Selects links on mouse over


}

:active a:active { color: red; Selects the active link


}

You might also like