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

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

how does the page know to highlight the other tabs in the that color? for example.

<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>

the about, and contact sections don't have classes yet they highlight green.

1 Answer

Hi Nick,

This is to highlight the 'selected' page. A common practice is to style all navigation items to a particular style, and then use a 'selected' class to highlight the current page.

Your style would be something like:

  /* All navigation elements get these styles (incl. selected one) */
  nav a, nav a:visited {
      padding:15px 10px;
      font-weight:700;
      color:#FFF;
  }
  /* This is to highlight the current page */
  nav a.selected {
      color:#FC0;
  }