Chapter 3
Chapter 3: Up and Running with Selectors ..................................................................
In This Chapter
Getting serious about selectors
Using multiple declarations
Grasping grouping
Employing attributes as selectors
Building your first style sheet
Getting specific about CSS
N
ow that you’ve been exposed to the wonders of CSS, you’re unlikely to
continue to write this kind of HTML:
<h3><font color=”red”>Warning:</font></h3>
That’s the kind of line you’d have to write perhaps dozens of times in a Web
site. Say, for example, that you have a series of warnings throughout your
Web site, each preceded by an H3 headline in red. For eachheadline, you
had to specify that it was red using the <font>element.
Along comes CSS. Now you can create a single H3 selectorin a single location,
yet it affects all the H3 headlines throughout the entire Web site. That one style
makes all H3 headlines red automatically. If you later decide to change H3 head-
lines from a red color to simply boldface, no problem. You need to make that
change only once in the style sheet rule instead of dozens of places to H3 ele-
ments scattered throughout the HTML code.
A selector specifies to which element in the HTML code a CSS style rule is
applied. For example, use the selector pif you want a rule applied to HTML
paragraph <p>elements. Or use the selector h1to define a CSS rule that is
applied to the H1 headline elements in the HTML code. In other words, a CSS
selector is just an HTML element with its < >symbols stripped off. Here’s an
h1selector (shown in boldface), within a CSS rule: