Jump to content

CSS Specificity page


Recommended Posts


There are two statements on that page that I can't wrap my head around:


"Equal specificity: the latest rule counts - If the same rule is written twice into the external style sheet, then the lower rule in the style sheet is closer to the element to be styled, and therefore will be applied:

h1 {background-color: yellow;}
h1 {background-color: red;}"

In what sense is the rule "closer to the element"? It comes last (so it's logical that it overrides any previous rules with the same specificity), but I don't know in what sense it's "closer". 


"Contextual selectors are more specific than a single element selector  - The embedded style sheet is closer to the element to be styled."

I've no idea what the underlined statement means here. How is a selector in an external file a "single element selector"? Doesn't the embedded selector also select a single element (the same one)? And how is that related to being "closer"?


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...