CSS classes and ids



Readings

Castro covers some of this material in a rather different way in castro6.gif Chapter 9.

Consistency--who needs it?


For these two snapshots, certainly one is more 'scannable':
For the Ask.com page....

Using type formatting consistently: CSS classes


Creating a class


A CSS class is a re-usable collection of style rules that can help you:

Here's how you could define a collection of rules to make text have that green appearance that Ask, Google and others to display the address of a search result. Put this definition in your stylesheet, or wherever you define your style rules:
.siteURL {
   color: #green;
   font-weight: bold;
   font-size: x-small;
}
.highlightbox {
   background-color: #fde;
   border: 1px solid #666
}
Note that:


Applying a class


To apply a class to some text, we might use the <span> tag like this...
<p>J. K. Rowling's site is at
<span class="siteURL">www.jkrowling.com</span>. There is...

But the class attribute can also be put in lots of other tags.
<ul class="highlightbox"><li>Don't use a class when....</ul>




Multiple classes

You can apply more than one class at a time. For example:

<div class="gradedBackground photoBox">

This allows you to have some classes that are used for positioning and other classes that are used for text formatting, and then mix and match.

Classes (or IDs) in DreamWeaver

Go to Window | CSS Styles to display the window that lets you edit/create classes in DreamWeaver.

You can right-click in the CSS Styles window to create a new style:

After you create the class/ID it will be available from the Properties window to be applied to text.

id, a unique 'class'

The main difference between ids and classes is that ids are meant to be used just once on a page. We might use them for...

The following shows how an id is defined and applied:

Defining an id

#mycontentbox {
   margin-left: 100px;
   margin-right: 100px;
   background-color: #fff;
}

Applying an id


<div id="mycontentbox">
.
.
.
</div>