CSS Selectors

CSS selectors are used to declare which of the markup elements a style applies to, a kind of match expression. Selectors may apply to all elements of a specific type, or only those elements that match a certain attribute; elements may be matched depending on how they are placed relative to each other in the markup code, or on how they are nested within the document object model.

Common selectors are the id selectors which use a hash sign to indicate the, class selectors which use a period to indicate the  , and type selectors which use the node name of an element to indicate the type. There are also Universal CSS Selectors.

Pseudo-classes and pseudo-elements are also CSS selectors.

Examples:


 * ID selectors...

 color:red; }
 * 1) id {

p#1 { color:blue; } Red text. Blue text.


 * Class selectors...

 .class { color:green; }

p.1 { color:yellow; }

.2 {   background-color:black; } Green text on black bg. Yellow text. Text on black bg. Green text.


 * Type selectors...

 p { color:red; }

span, div { color:green; } Red text. Green text. Green text.