!important and Maintenance
Introducing even one uncommented important declaration into an author style sheet
has a huge negative impact on the style sheet??™s maintainability, so it should be used
with care. The only way to overwrite an important declaration is by using even
more important declarations??”an approach that soon becomes unmanageable. A
The Cascade, Specificity, and
Inheritance
style sheet that??™s littered with important declarations often signals that an author
hasn??™t thought clearly enough about the structure of the CSS.
The Ultimate CSS Reference 126
Specificity
Specificity is a mechanism within the CSS cascade that aids conflict resolution.
The concept of specificity states that when two or more declarations that apply to
the same element, and set the same property, have the same importance and origin
(p. 118), the declaration with the most specific selector will take precedence.
Consider this example:
p {
color: black;
background-color: white;
}
div.warning p {
color: red;
}
div#caution p {
color: yellow;
}
body#home div p {
color: white;
}
The above example style sheet contains four style rules that have a selector that
matches p elements.
Pages:
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194