Cascading Style Sheets

Peter Wood

Cascading Style Sheets (CSS)

Embedded Style Sheets

External Style Sheets

Multiple Selectors

Contextual Selectors

Styles based on class and id attributes

Combining selectors

Further CSS selectors

Selector Example Selects ...
.class .keyword all elements with class="keyword"
#id #123 the element with id="123"
* * all elements
element p all p elements
element, element div, p all div elements and all p elements
element element div p all p elements inside div elements
element > element div > p all p elements whose parent is a div element
element ~ element p ~ ul all ul elements having a p element as a preceding sibling
[attribute] [style] all elements with a style attribute
[attribute = value] [type="text/javascript"] all elements with type="text/javascript"
[attribute ^= value] a[href ^= "http"] all a elements whose href attribute value begins with "http"
[attribute $= value] a[href $= ".pdf"] all a elements whose href attribute value ends with ".pdf"
[attribute *= value] a[href *= "bbk"] all a elements whose href attribute value contains "bbk"

Some other CSS properties

Property Some values Meaning
font-size large, 24px px is pixels, also cm, ...
font-family arial, serif, sans-serif specific like arial, or generic like serif
font-style normal, italic
font-weight normal, bold
display block, inline
margin-top 1cm, 2em em is the size of the letter m
line-height normal, 2 2 is twice the current font size
text-decoration underline, line-through
list-style-type circle, lower-alpha circle for ul, lower-alpha for ol

Links to more information