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

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

Basic CSS Syntax issue: How to make the navigation links a certain colour when on a particular page ?

When I'm on a certain page, I want that link to be black.

I wrote this but it doesn't work. The hover function works though.

nav a:selected, nav a:hover{ color:#000; }

4 Answers

Hi Tobi,

There is no :selected pseudo class unfortunately. And there isn't a pseudo class which will do what you are asking.

So I would suggest creating a class, such as .selected, and applying that to the relevant links on each page.

For example -

HTML

<nav>
   <a class="selected">Home</a>
   <a>Contact</a>
   <a>About</a>
</nav>

(This would be your home page)

CSS

nav a.selected {
   color: black;
}

Hope that helps,

Ede

hello , you maybe should add class to your html tag

best regards

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

How would that look? Thanks

for example in your html file :

  <a href="#home" class="home">click me</a>

then in your css file

.home{color:#000;} .home:hover{color:#C9C9C9;}

and in your html file where you want to change the color

add a script tag just before the body end tag:

<script>$(document).ready(function(){

$('.home').css('color','#FF0000;');

};  </script>

Happy Coding

No problem,

Glad it helped. There's some useful information on different pseudo classes to do with links here -

http://www.w3schools.com/cssref/sel_active.asp

All the best,

Ede