Define and Apply CSS Classes and IDs Elements

  • Class style rules are defined in the head element.
  • CSS rules are between the style element <style type="text/css"> </style>
  • Classes are created to individualize styles
  • Each class begins with a period followed by the unique class name.
  • Classes are applied to any xhtml element or text block using div and span selectors.
  • No programming terms can be use as class names.
  • When applying the classes, the period is not used and the name is quoted.

<style type="text/css">
.mid {text-align:center}
</style>
In the body:
<div class="mid">Centered Text<div/>

CSS ID Selector -   #idname {property:value}

  • IDs are defined in the head between the style elements <style type="text/css"></style>
  • IDs begin with a pound sign (#) an a unique term.
  • IDs are used only once on a page.
  • Apply the ID term without the pound sign
  • Applied to any xhtml element, div or span elements
  • These special selectors allow JavaScript functions to manipulate objects defined with the pound sign.

  <style type="text/css">
#lively{font-family:Zapf Chancery}
</style>
In the body:<span id="lively">This is fancy text.</span>


Define Classes and IDs
Div and Span Elements
Pseudo Classes
Background Images
Drop Caps
Drop Shadow
Display Attributes
Background-Attachment
Web Design with XHTML Part II
Prince George's Community College
Doris Cuffey, Instructor