Note the exclamation point
STYLIN??™ WITH CSS - CHAPTER 2 58
Charlie??™s Simple Cascade Summary
You need to remember just three things in this simpli?¬? ed version of the Cascade rules. These are true for virtually every
case.
Rule 1: Selectors with IDs override selectors with classes; these, in turn, override selectors with only tags.
Rule 2: If the same property for the same tag is de?¬? ned in more than one location in the Cascade, inline styles override
embedded styles, which override style sheet styles. Rule 2 loses out to Rule 1, though??”if the selector is more speci?¬? c, it
overrides, wherever it is.
Rule 3: De?¬? ned styles override inherited styles, regardless of speci?¬? city. A little explanation is required for Rule 3. This
markup
Inheritance is weak in the Cascade
and this rule, which has a high speci?¬? city,
2 - 0 ??“ 4 html body div#cascadedemo p#inheritancefact {color:blue:}
results in all the text, including the word weak, being blue because the em inherits the color from its parent, the p tag.
As soon as we add this rule for the em, even though it has very low speci?¬? city
0 - 0 - 1 em {color:red}
the em text is red. The inherited style is overridden by the de?¬? ned style for the em, regardless of the high speci?¬? city of
the rule for the containing paragraph.
Pages:
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95