Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialElina Zois
Courses Plus Student 946 PointsIf 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
28,149 PointsThe 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/
Elina Zois
Courses Plus Student 946 PointsOkay i see. that makes total sense. Thank you so much!
web pad
4,483 Pointsweb pad
4,483 PointsThank 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?