Maybe your idea of specificity doesn't work a bit. Specificity should be a contextless idea: since CSS can be loaded independently of HTML, you don’t need an HTML document to guess which rule is more “specific”. Consider another example:
<div id="inner"> <div id="container"> <h1>Hello World!</h1> </div> </div>
With this snippet, you have to go against your initial assumption that inner
should be more specific. This means that your interpretation needs a context (which CSS does not have).
Point, both rules are visible with the same specificity ( h1
descendants of the element identified by id
), and the selector does not give higher priority to closer descendants.
If two rules of equal specificity are applied, the winner is the last declared in CSS.
zneak
source share