Jump to content
Sign in to follow this  

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"?


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...