Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS The Selectors Solution

Adriana Karlak
Adriana Karlak
1,449 Points

The color I set for the visited links is being applied to the links before they've been visited. Why?

This is what my CSS code looks like:

/* Create visited and hover styles for all links inside 'main' */

main a:hover { background-color: skyblue; }

main a:visited { color: red; }

The 'a:hover' declaration works just fine. When I hover over the links, the background color changes, as it should.

But the 'a:visited' selector isn't working right. The links are red before I've even clicked them as while as after. They should only be red AFTER, not before.

In an effort to fix this, I experimented by making the property and value for the 'a:visited' selector different. I set the background-color to orange. What that did was even stranger. It made the background color of those links change to orange only when I hovered over them! Which is strange, because the selector I was style is not a ":hover" selector, it's a ":visited" selector.

Can anyone tell me what I'm doing wrong? Or if it's supposed to be doing this? Because I don't think it is. This is the first problem I've had with this course so far.

2 Answers

In my experience that is because the browser thinks you have visited the link. Try a new browser window with cleared history to reset.

Adriana Karlak
Adriana Karlak
1,449 Points

I thought of this too. I also thought maybe I HAD opened the links and I just forgot. So I experimented and added an entirely new link to the HTML (making sure it was in the main tags) to see if the CSS would style it how it was supposed to. It still did the same thing though when I opened and refreshed the page. So that is not the issue.

I have the same issue.