Software Sue

Link to Simply Sue
Link to Sustainability Sue
location: software/stylesheets/css/selectors Skip navigation : Home  

CSS selectors


There are 4 types of selectors: simple (single HTML elements), 'in context' (multiple HTML elements), CLASS (a group of elements), or ID (a subgroup of elements).

Simple selectors

A single HTML element, such as H2, P, or B. For example:

H2 {color:green;} will set the colour of every header 2 in the document to green. In this rule, 'H2' is the selector, and {color:green;} is the declaration.

To set all the headers:

H1,H2,h3,H4,H5,H6 {color:green;}.

Properties may be grouped for some properties, for example:

H2 {font: 10pt Courier italic;}

In context selectors

You can be more specific in defining which element you want to assign a style to. For example, to identify any italic tag contained within a paragraph tag, select P I.

P I {color:blue;}

CLASS selectors

The term CLASS identifies a grouping of elements. A period is written in front of the CLASS name.

CLASS .classname {color:red;}

ID selectors

The term ID identifies a smaller set within a CLASS, though it may sometimes be used interchangeably with CLASS. A hash mark or pound sign is always written in front of the ID name.

ID #IDname {color:green;}

Note: There should only be one tag in a document that specifies a particular ID.