-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Mastering CSS
By :

We're beginning to understand how a modular approach to CSS allows us to use classes as little chunks of CSS that can be used anywhere on the web page to style any element. This makes writing CSS very convenient. However, it only works if the CSS is kept lightweight. As you'll learn in this section, every CSS selector can be weighed on a scale, and the heaviest selector wins the style battle between two competing selectors. So, I'll start by explaining the weights of different selectors and how they can overrule one another. Then, we'll talk a bit about how the universal selector and the !important
declaration fit into the weights of the selectors.
All selectors are assigned a weight, and the heaviest selector takes precedence when conflicting CSS rules exist. It's natural when architecting a website that you have general styles that get overridden with more specific styles in different circumstances. In the global area at the top of the...