Cascading Style Sheets

Three ways to style:

  1. External style sheets
  2. Document level styles within the<head> section:
    <style type="text/css">
    body {background: url(marble.gif);}
    h1 {color: gray;}
    </style>
  3. Inline styles within the <body> section (depreciated):
    <p style="color: gray;">

Grouping Selectors

h2, p {color:gray;}

Universal Selector (*)

* {color:gray;}

This makes every single element in the document gray

Grouping Declarations

h1 {font: 18px Helvetica; color: purple; background: aqua;}

Grouping Everything

h1, h2, h3, h4, h4, h6 {color: gray; background: white; padding: 0.5em;}

Class Selectors

*.warning {font-weight: bold;}
<p class="warning">
(* is universal selector, . is class selector)

.warning {font-weight: bold;}
<p class="warning">
(* can be ommited)

p.warning {font-weight: bold;}
<p class="warning">

Multiple Classes

.warning.urgent {background: red;}
(class attribute must contain both warning and urgent to match)

ID Selectors

Preceeded by an octothorpe (#) instead of a period (.)
Each ID value can only be used once within a document

*#first-para {font-weight: bold;}
<p id="first-para">

#first-para {font-weight: bold;}
(* can be ommited)


Send mail to the Webmaster

logo This site best viewed with a browser
Warning: This is a Debian centric site
Many thanks to Debra and Ian Murdock for making Debian possible
First created Apr 22, 2008 ~ Last revised August 31, 2009

Valid XHTML 1.0 Strict Valid CSS!