Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS specificity selector: element selector overrides pseudo class

Im new in CSS, i was learning about CSS element specificity, and I know that at the end the selector with more specificity will be applied, but how about this case:

this supposed to be more specific

    header: first-child {
        color: red:
    }

why is not applied???

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Specificity only affects the element that is selected.

h1 { color: blue; } is not competing with header:first-child { color: red; } because they target different elements.

h1 { color: blue; } is competing with h1 { color: inherit; } from the browser’s default stylesheet (and wins because author stylesheets beat browser stylesheets).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading