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

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

Keith Grimes
PLUS
Keith Grimes
Courses Plus Student 2,356 Points

Why can't you access the targeted element with a css rule of .selected? Why use preceding elements "nav a.selected"

In the video you target an anchor element within the nav structure labeled by class "selected" by creating a css selector called "nav a.selected" I understand this is a very targeted selection but it seems like it would be easier just to create a css rule called .selected.

Why do you have to include the entire path to the target?

1 Answer

Tomas Pavlik
Tomas Pavlik
26,726 Points

Hi, Keith, you can only use .selected class selector if you want, but the class might also be used somewhere else in the html document, targeting is therefore much safer. Moreover, you can then easily read your code (you know pefectly that selected class is inside nav etc..)