Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML How to Make a Website Customizing Colors and Fonts Use Classes in CSS

If CSS follows a cascading approach to the rules defined, why is the text in header and section not grey?

Thus far, we have set rules to make the color of the text in header white and the color of all anchors across the index.html page green. When the last rule is broad and is to set the color of the text in the <body> section grey, why isn't this last rule applicable across all elements within the <body> section? Currently, it seems to apply the grey only to the bullets of unordered list and the footer?

2 Answers

Kevin Korte
Kevin Korte
28,111 Points

The answer is CSS specificity. Yes CSS cascades, so in the event that two rules have the same specificity, the rule defined later in the selection sheet will be the one that overrides, and is shown.

However, specificity beats cascading every time. What does this mean?

The rule body { color: #999; } only has a specificity of 1.

However nav a { color: #fff; } has a specificity of 2, so it overrides the the body rule, even though it came first.

I highly recommend reading this article to understand this concept more: https://css-tricks.com/specifics-on-css-specificity/

Thank you for this info. In Specificity, does nav belong in the category of tag names? Each tag name has a value? And body has a value of 1, and nav has a value of 2?

Okay i see. that makes total sense. Thank you so much!