You may be wondering what other
values properties such as font size
and color may have. For example,
you might want to know if you can
specify a color using RGB (red, green,
blue) instead of a color name. (The
answer is yes, you can.) For now, just
hang in there while I focus on showing
you how selectors work. Then,
later in this chapter, I??™ll show you the
declaration part of the rules.
STYLIN??™ WITH CSS - CHAPTER 2 34
Targeting Tags Within the Document
Hierarchy
If you have forgotten what the document hierarchy is since the end
of the last chapter, you might want to reread ???Document Hierarchy:
Meet the XHTML Family??? in Chapter 1 now so that I can avoid the
redundancy of repeating myself repeatedly and redundantly.
Using Contextual Selectors
If you write a rule where you simply use the tag name as the selector,
then every tag of that type is targeted. For example, by writing
p {color:red;}
every paragraph would have red text.
But what if you only want one particular paragraph to be red? To
target tags more selectively, you use contextual selectors. Here??™s an
example
div p {color:red;}
Now only paragraphs within div tags would be red.
As you can see in the example above, contextual selectors use more
than one tag name (in this case, div and p) in the selector. The tag
closest to the declaration (in this case the p tag) is the tag you are
targeting.
Pages:
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66