Lecture Notes 4b:
CSS Classes

CSE 190 M (Web Programming), Spring 2007

University of Washington

Reading: Sebesta Ch. 3 sections 3.2 - 3.3, 3.4.2 - 3.4.4, 3.12

Valid XHTML 1.0 Strict Valid CSS!

CSS class selectors

p.special {
    background-color: yellow;
    font-weight: bold;
}

The HTML class attribute

<p>Spatula City!  Spatula City!</p>
<p class="special">See our spectacular spatula specials!</p>
<p class="special">Today only: satisfaction guaranteed.</p>
<p>We'll beat any advertised spatula price!</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

Today only: satisfaction guaranteed.

We'll beat any advertised spatula price!

Class selectors without element

.standout {
    color: red;
    font-family: cursive;
}

HTML class attribute revisited

<h2 class="standout">Spatula City!  Spatula City!</h2>
<p class="special">See our spectacular spatula specials!</p>
<p class="special standout">Today only: satisfaction guaranteed.</p>
<p class="standout">We'll beat any advertised spatula price!</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

Today only: satisfaction guaranteed.

We'll beat any advertised spatula price!


CSS ID selectors

p#missionstatement {
    font-style: italic;
    font-family: "Garamond", "Century Gothic", serif;
}

The HTML id attribute

<p>Spatula City!  Spatula City!</p>
<p id="missionstatement">Our mission is to provide the most
spectacular spatulas and splurge on our specials until our 
customers <q>esplode</q> with splendor!</p>

Spatula City! Spatula City!

Our mission is to provide the most spectacular spatulas and splurge on our specials until our customers esplode with splendor!

Linking to sections of a web page

<p>Visit <a href=
"http://www.textpad.com/download/index.html#downloads">
textpad.com</a> to get the TextPad editor.</p>
<p><a href="#mac">Directions for Mac OS X</a></p>

Visit textpad.com to get the TextPad editor.

Directions for Mac OS X


Logical divisions in HTML: <div>

a section or division of your HTML page (block-level)

<div class="standout">
<h2>Spatula City!  Spatula City!</h2>
<p class="special">See our spectacular spatula specials!</p>
<p>We'll beat any advertised spatula price!</p>
</div>

Spatula City! Spatula City!

See our spectacular spatula specials!

We'll beat any advertised spatula price!


Inline styling sections: <span>

an inline element used purely as a range for applying styles

<h2>Spatula City!  Spatula City!</h2>
<p>See our <span class="special">spectacular</span>
spatula specials!</p>
<p>We'll beat <span class="standout">any advertised 
spatula price</span>!</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

We'll beat any advertised spatula price!


Embedding style sheets: style

<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>

Inline styles: the style attribute

<p style="font-family: sans-serif; color: red;">
This is a paragraph</p>

This is a paragraph


Cascading style sheets

Practice problem

Add styling to the web page stored as digg.html to make it look like this:

Digg ripoff

  • 11pt Arial font
  • article background #EEEEEE
  • heading color #105CB6
  • popular color #A1295A
  • diggs background #FFF3B1