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 CSS Basics (2014) Basic Selectors Pseudo-Classes

Tony Brown
PLUS
Tony Brown
Courses Plus Student 1,678 Points

a:focus is not working for me. All the other pseudo-classes are, however. What gives?? :-)

Here's what I have in the stylesheet of my newly opened workspace:

a:link { color: orange }

a:visited { color: lightblue; }

a:hover { color: forestgreen; }

a:active { color: lightcoral; }

a:focus { color: white; background-color: orange; }

Any thoughts?

Scott Chen
Scott Chen
8,026 Points

I have the exact same problem when I do it on Firefox (I'm using a 2011 Macbook Pro). However, the "tabbing" works when I open workspace up with Chrome, so it seems to be a browser issue.

3 Answers

William Crawford
William Crawford
4,319 Points

Thanks to Tony Brown's answer above, I got mine to work - need to use option-tab to tab thru links on my MBP.

Hi Anthony,

What is it that you would like / are expecting a:focus to do? The focus selector can be applied to elements that accept keyboard events or other user inputs. It is common in things like form elements. Such as when you click in a text field and the background colour changes or a border is applied. The element comes into 'focus'.

It can also be used on link elements - you will see it in action if you use your tab button to navigate through the elements in your page. Tab to the link element and when it is selected your CSS should take action. Of course, navigating like this is generally less common than using a mouse, therefore this effect is perhaps not so useful. But can be done all the same.

Hope this helps,

Ede

Tony Brown
Tony Brown
Courses Plus Student 1,678 Points

Hi Ede, thanks for responding. That's precisely it though. I'm trying to get the links to light up when I tab through them like on the video. Undoubtedly, this is the least important pseudo-class of the bunch, but it works in Guil's video. And, admittedly, I am one of those weirdos who does enjoy a nice tabbing through his links every now and again.

Any ideas why a:focus is not lighting up my links when I tab through them?

Hi Anthony,

In that case, that is strange then. Could you post all your CSS and HTML and I will try it myself.

Ede

Tony Brown
Tony Brown
Courses Plus Student 1,678 Points

Hey Ede, I figured it out! It occurred to me that my tab button was probably configured differently. When I hold down option and then tab through, my links get highlighted. I have a 2014 MBP. I wonder if they macs are set to do that...?

looks like you're a:link is missing a semi-colon.