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 trialjared eley
Courses Plus Student 429 PointsMy Nav buttons don't highlight when I select them?
My selected link pages doesnt highlight when i select it.
3 Answers
Jake Cooper
Courses Plus Student 56,854 Pointsin your stylesheet you have a few pseudo classes you can change for your anchor elements, something like this:
a :hover{ color: #333; }
the others are: a :link{} a :visited{}
this should do the trick, if not check syntax :)
Terrell Stagner
3,446 PointsHere are some selectors that may help you.
/* unvisited link */
a:link {
color: green;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: red;
}
/* selected link */
a:active {
color: yellow;
}
jared eley
Courses Plus Student 429 PointsThat helped thanks but how do i get it to stay highlighted when im on one of my pages so that the user knows what page they are on.
Terrell Stagner
3,446 PointsIf you have not found the video yet here it is talking about adding classes.
I do recommend watching the videos in order if you are trying to learn how to build a web sites.
Good luck.
Shawn Denham
Python Development Techdegree Student 17,801 PointsThere are of course several ways to skin that cat but most often people use jQuery to compare the current URL you are at in your browser with the URL you have in your <a> tag in the <li> link that you clicked.
Here is a quick and dirty example
$(document).ready(function () {
var url = window.location;
$('.nav li a').each(function () {
if (this.href == url) {
$('.nav').find('.active').removeClass('active');
$(this).parent().addClass('active');
}
});
});
Taken in a line by line basis we have the following:
$(document).ready(function () {
var url = window.location;
This is saying when the document loads take the current URL and store it in the variable called url.
$('.nav li a').each(function () {
if (this.href == url) {
$('.nav').find('.active').removeClass('active');
$(this).parent().addClass('active');
This last block is the meat and potatoes of the jQuery script. it is saying go though each <a> tag in the navigation list, if the any of them are the same as the URL stored in the url variable remove the .active class wherever it is and apply to this <li>.
Like I said, this a quick and dirty way I came up with at 2am. I am sure there are more elegant and cleaner ways to get it done :) but hopefully this gives you the jest of what I am talking about.
Here are some other ways:
and one from Jessie's
I hope this helps!