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
David Schriever
1,777 PointsWhen selecting links (anchors)
Hello I have a question,
when I want to change the color of a link, how come I have to write, for example:
nav a { color: blue; }
istead of simply
nav { color:blue; }
Why doesn't that simply change all text colors inside my nav element to blue?
1 Answer
Craig Watson
27,930 PointsHi,
browsers themselves render default styles, if you take a look at the CSS of the anchor elements using your browsers inspector you will see the styles set by the browser before you even get a hold of it.
The browser is more specific by selecting all <a> tags, so in turn you need to be more specific than that or simply override it.
Example:
a {
color: red; /* Turns all anchor elements to red by default overriding the browser default */
}
nav a {
color: green; /* Turns all anchors in the nav element green but not any anchors outside a nav element */
}
Hope this helps in some way! Craig
David Schriever
1,777 PointsDavid Schriever
1,777 PointsThank you! that makes total sense.