by Jim Gordley
Class selectors allow you to name your own elements but unlike id selectors they do not have to be unique.Class selectors can be shared amoung any element on in you HTML document. For example you want some text to be red without affecting other text in your document.
You learned erlier that creating an id is done by using the # symbol. Creating a Class selector is done by using the period symbol (.)
Class selectors should be given logical names according to how they relate to the document. Lets say you have some text that you want to have a green hue and you make this happen using a class name of green. You now have a document or several documents that have elements with a class attribute of green.
Next month you want to change that color to blue. It is an easy thing to do by simply changing the style sheet, but now you have blue text in any element that has green as it's name. It would make more since and be much easier to have a logical name like
|DO THIS||WHY YOU DO IT||
||This opens the index.html file for editing.
Assigns the class attribute with a value of "heading" to the <h2;> element
Assigns the same class atribute to the <h3> element
Opens the styles.css file for editing.
Creates the class selector that makes any element that has a class attribute with a value of heading to be light gray.
|Notice that both headings share the same gray background. Using one class selector.|