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

Why does only one of the navigation links get the class selection?

I'm doing the How to Make a Website exercise, and the teacher gives the class selection to one of the navigation links. Why doesn't he give it to the rest of the navigations? How does the browser know what to have selected? I know the class selector is in the css but in the html it chooses one link to style. Can somebody help me?

3 Answers

Well, you're writing static pages, so when you write the next page you assign the class to a different navigation link. In dynamically written pages you could assign the class based on the page itself. The class doesn't have to be assigned to the same navigation link on every page, you decide what link gets the class.

Grant Bates
Grant Bates
1,915 Points

When you create the other pages (about, contact) those pages will then get the classification and the index page will not. The other pages will copy the index.html as a starting point. This caused a problem for me too but eventually it will all be explained.

I believe the class is assigned to the link that corresponds to the current page so you can format the link slightly differently. (More advanced, you can create the class so that the link 'won't work' on the page so people don't click on the link to a page where they already are)

Why not just add that class to the nav which would affect all three of the navigation links, instead of adding it to just one of the actual links itself? Would that work?

Assigning a class to the nav (let's call it navclass) and then writing something that affects all the links in it is possible sure

.navclass a {

But that styles ALL the links in the nav, and by assigning a class (or id more specifically makes sense in this instance) to a specific link makes that link different than the rest.

Are you trying to style all links in the nav or one link specifically?

I'm still confused, what if you go to another page? I know that you can't in this case because the links are broken, but if you could wouldn't you want the .selected feature to apply to any page that you could select? It seems like this code only allows profile to be selected no matter what you do.