Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll just toss in a link to the CSS 2.1 spec itself, and how browsers are <em>supposed</em> to calculate specificity:</p> <p><a href="http://www.w3.org/TR/CSS2/cascade.html#specificity">CSS 2.1 Section 6.4.3</a>:</p> <blockquote> <p>A selector's specificity is calculated as follows:</p> <ul> <li>count 1 if the declaration is from is a 'style' attribute rather than a rule with a selector, 0 otherwise (= a) (In HTML, values of an element's "style" attribute are style sheet rules. These rules have no selectors, so a=1, b=0, c=0, and d=0.)</li> <li>count the number of ID attributes in the selector (= b)</li> <li>count the number of other attributes and pseudo-classes in the selector (= c)</li> <li>count the number of element names and pseudo-elements in the selector (= d)</li> <li>The specificity is based only on the form of the selector. In particular, a selector of the form "[id=p33]" is counted as an attribute selector (a=0, b=0, c=1, d=0), even if the id attribute is defined as an "ID" in the source document's DTD.</li> </ul> <p>Concatenating the four numbers a-b-c-d (in a number system with a large base) gives the specificity.</p> </blockquote> <p>If the specificities are equal, then <a href="https://www.w3.org/TR/CSS2/cascade.html#cascading-order">CSS 2.1 Section 6.4.1</a> comes into play: </p> <blockquote> <ol start="4"> <li>Finally, sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins. Declarations in imported style sheets are considered to be before any declarations in the style sheet itself.</li> </ol> </blockquote> <p>Note that this is talking about when the style is defined, not when it is used. If classes <code>.a</code> and <code>.b</code> have equal specificity, whichever is defined last <strong>in the stylesheet(s)</strong> wins. <code>&lt;p class="a b"&gt;...&lt;/p&gt;</code> and <code>&lt;p class="b a"&gt;...&lt;/p&gt;</code> will be styled identically, based on the definition order of <code>.a</code> and <code>.b</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload