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 Adding Pages to a Website Add a New Page

Trouble with "Selected" links

In the video, Mark shows us that the nav links will stay their highlighted color to show the visitor what page they are on. My links are highlighted correctly when hovering, but it goes back to it's regular color when I'm not hovering. Any idea what I'm doing wrong that the "selected" nav link doesn't stay highlighted while visiting that certain page?

10 Answers

You have class: when it should be class=

Hi Paul,

It sounds like you have a problem with the "selected" class in your main navigation.

Here's the nav from index.html:

<nav>
        <ul>
          <li><a href="index.html" class="selected">Portfolio</a></li>
          <li><a href="about.html">About</a></li>
          <li><a href="contact.html">Contact</a></li>
        </ul>
      </nav>

Notice that the index link has the "selected" class. On each new page that you have you need to move that class to correspond to which page you're on.

Thanks Jason,

I looked again and found that I have that done correctly. In my "index.html" page the index link has the 'selected' class, and so on for the About and Contact pages.

What about your css then?

What do you have for your selected class?

From main.css:

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

This is what's responsible for setting the color on both the hover state and the link that has the "selected" class.

Perhaps check if you've accidentally added a space nav a .selected

Or spelled it wrong

Here's what my CSS looks like. Maybe I'm overlooking something?

'''CSS /******************************** COLORS *********************************/

/* site body */ body { background-color: #fff; color: #999; }

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

/* nav background on mobile */ nav { background: #800000; }

/* selected nav link */ nav a.selected, nav a:hover { color: #000; }

/* nav links & logo text*/ a, h1, h2 { color: #fff; } '''

Obviously I don't know how to make my code appear the same way you did in your previous examples too... :/

Here's a discussion on how to post code in the forums: https://teamtreehouse.com/forum/posting-code-to-the-forum

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

The hover part works. The font just won't stay black when you're on that particular page. It's as if the class part just isn't working...

Can you post the html for the nav for one of your pages? The forums will strip out html so check the link I provided.

Your css looks correct.

Here's the html for the home page:

<nav>
          <ul>
            <li><a href="index.html" class:"selected">Portfolio</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="Contact.html">Contact</a></li>
          </ul>
        </nav>

And from the about page:

<nav>
          <ul>
            <li><a href="index.html">Portfolio</a></li>
            <li><a href="about.html" class:"selected">About</a></li>
            <li><a href="Contact.html">Contact</a></li>
          </ul>
        </nav>

And the Contact page:

<nav>
          <ul>
            <li><a href="index.html">Portfolio</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="Contact.html" class:"selected">Contact</a></li>
          </ul>
        </nav>

Thanks again, by the way, for your help on this. I'm not sure what's going on. I know some parts in this particular track have disclaimers that stuff might not work correctly on Firefox. I've tried it with Safari too though and it's still doing the same thing.

You're welcome.

It's my fault. I should have asked for both html and css in the beginning and it would have saved some back and forth.

I mentioned the problem in another answer here.

Also, be careful, you have href="Contact.html" Change to lowercase 'c'

You have used a colon instead of equal sign.

Should be class="selected" not class:"selected"

Good God... duh... I knew it would be something miniscule like that. Thanks so much!!!