Prev | Current Page 61 | Next

Charles Wyke-Smith

"Stylin' with CSS: A Designer's Guide 2nd Edition"


The words ???same class??? in the headline are now also italicized. By
deleting the p from the start of the selector, you remove the requirement
for the class to be attached to any speci?¬? c tag, so now both
span tags are targeted. The rule states that the span tag can be a
STYLIN??™ WITH CSS - CHAPTER 2 42
descendant of any tag with the specialtext class because no tag is
speci?¬? ed.
The bene?¬? t of this approach is that you can use a class without
regard for the tag to which it belongs, so you are escaping the inherent
constraints of the hierarchy when you do this.
The downside is that other tags that you don??™t intend to style might
also be affected because this modi?¬? ed rule is less speci?¬? c than it
was. So, say you later added a span inside another tag that also had
the specialtext class, such as this one:
In this div, the span tag may
or may not
be styled.

The text within the span would be italicized also, which may or may
not be the desired effect (Figure 2.13).
FIGURE 2.13 The less speci?¬? c the
selector, the more likely other tags
will be inadvertently targeted.
If you don??™t want to style this new div??™s span, you can adopt a second,
more focused, group selector approach, like this (Figure 2.14)
p.specialtext span, h1.specialtext span {font-style:italic;}
Now only the two tags in question are targeted and your new tag is
not affected.


Pages:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73