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 trial

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

Question about Text color in <body> element.

Hi Team,

This is my first post on team tree house, before I ask my question I want to say that you guys are doing one amazing job here. Thank you all for making these courses in such an efficient manner.

Coming to my question. In the end part of this video you choose the body element and changed the color property to #999. As per my understanding from previous videos due to the cascading nature of CSS all the text in the body element should turn out to be grey, but that does not happen. Only the text in the footer is changed. Rest of the text in the anchors, image descriptions does not change. Can you explain why is that happening?

Regards, Nawaz.

5 Answers

Tim Knight
Tim Knight
28,888 Points

Hi Nawazikram, welcome to the forum!

You're correct that by adding a color property to the body like #999 would change all of the text to gray. However, it might be likely that there are other styles that are coloring your text. For example in the challenge on hexadecimal colors, you style the h1, h2, p, and a elements with specific colors. Because of the cascade, the specificity of those color declarations would override the declaration on the body for those specific elements.

If that doesn't answer your question, please post the code you're having trouble with so I can be more specific.

Hi Tim,

Thank you for Answering my question. So what I understand is since the text in the anchor, h1, h2 elements were not changed due to specificity. As per the code below styling of body element comes at the end, but since other body elements though they were applied before the last element that change was not displayed due to specificity.

I hope I was clear, but I think I get the point. Disregard to answer this if you find it confusing. I will do a better job typing in future.

'''a { text-decoration:none }

wrapper{

max-width:940px; margin: 0 auto; padding: 5% 5%; }

logo{

text-align:center; margin:5%; }

a { color:#6ab47b; }

header{ background: #6ab47b; border-color:#599a68; }

h1, h2{ color:#ffffff; }

nav{ background:#599a68; }

nav a, nav a:visited{ color:#fff; }

nav a.selected, nav a:hover{ color:#32673f; }

body{ background:#fff; color:#999; }'''

Tim Knight
Tim Knight
28,888 Points

Hi Nawazikram,

You're definitely on the right track. Yes because your other CSS selectors are assign colors for the a, h1, and h2 anything you assign to the body will on impact the elements that don't already have color. It's not because of the cascade... it's because h1 is more specific than body in the document. Does that make sense? If you later added a declaration for the p element all of those too would overwrite the body's color declaration regardless of their placement in the CSS file.

Absolutely, Makes perfect sense. Thank you so much for such a prompt reply.

Tim Knight
Tim Knight
28,888 Points

No problem at all. You're very welcome. Enjoy learning about CSS.