To fully comprehend CSS, one must grasp the concept of specificity outlined in Section 6.4.3: Calculating a selector's specificity. Here is a brief summary:
- Start with 1 if the declaration comes from a 'style' attribute.
- Count the number of ID attributes in the selector (= b).
- Tally the amount of other attributes and pseudo-classes in the selector (= c).
- Determine the count of element names and pseudo-elements in the selector (= d).
In simpler terms:
- Inline declaration style=""
- #myId {}
- .htmlactionlink {}
- a {}
The third point states that equal precedence is given to class and pseudo-class selectors. Refer to w3schools.com for more information.
This means that when calculating:
a:link is { a=0, b=0, c=1, d=1}
versus
.htmlactionlink is { a=0, b=0, c=1, d=0}
The a:link
rule takes precedence due to receiving points for both class and element name.
NOTE:
In my opinion, the most accurate solution would be:
.htmlactionlink:link, .htmlactionlink:visited ... {
color: red;
}
In this scenario, we have {c=2, d=0}, foregoing the ordering seen in A.htmlactionlink
{c=1, d=1}