HTML and CSS Reference
In-Depth Information
There are many ways to greet a person, but the words are not as important as the act
of greeting itself.
There is nothing finer than a hearty welcome from one's fellow man.
<p class="aside">
Although a thick and juicy hamburger with bacon and mushrooms runs a close second.
Figure 2-1. How different rules affect a document
In every case, the user agent determines which rules match an element, calculates all
of the associated declarations and their specificities, determines which ones win out,
and then applies the winners to the element to get the styled result. These machinations
must be performed on every element, selector, and declaration. Fortunately, the user
agent does it all automatically. This behavior is an important component of the cascade,
which we will discuss later in this chapter.
Universal Selector Specificity
As mentioned earlier, the universal selector does not contribute to the specificity of a
selector. In other words, it has a specificity of 0,0,0,0 , which is different than having
no specificity (as we'll discuss in “Inheritance”). Therefore, given the following two
rules, a paragraph descended from a div will be black, but all other elements will be gray:
div p {color: black;} /* 0,0,0,2 */
* {color: gray;} /* 0,0,0,0 */
As you might expect, this means that the specificity of a selector that contains a uni-
versal selector along with other selectors is not changed by the presence of the universal
selector. The following two selectors have exactly the same specificity:
div p /* 0,0,0,2 */
body * strong /* 0,0,0,2 */
Search WWH ::

Custom Search