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

James N
James N
17,864 Points

when I change a:focus to :focus, my entire page turns orange!!!

when I change a:focus to :focus, my entire page turns orange!!!

5 Answers

Merritt Lawrenson
Merritt Lawrenson
13,477 Points

':focus' is the psuedo-selector that selects what's currently in focus. This usually means something you clicked on, like a link or some text. The pseudo-selector has to attach to an element, in this case the 'a' element. Your browser is trying to get around the error and decided that since you have the page selected, you must want the whole thing orange.

:focus is an pseudo class you need to attach it with some kind of element i.e(a, button). Your whole page turn orange because you had not specified the element you want to target. So, the browser look for the element and when he not find one he will simply apply those styles to your root element which is html. That's why your whole page turn orange. I hope this will help :)

Brian Douglas
Brian Douglas
822 Points

Could you post the code you are using.

:focus is a pseudo selector so will need to be attributed to some element in order for it to take effect.

In the video, Guil specifically says that removing the "a" allows the ":focus" to apply to any element on the page that becomes active.

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

James, this code appears to be a problem in the Internet Explorer web browser. Is that what you are using?

I find that Treehouse videos and Workspace works best in Chrome, but Firefox seems to be adequate as well.

If you are using Internet Explorer, I recommend that you download a different web browser, and set the new browser as your default.

Isaiah Wojciechowski
Isaiah Wojciechowski
3,163 Points

i am having a similar problem except mine changes the background to orange (as it should) but not changing the text color to white

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

I've also tried using *:focus as the selector but the result is the same.

PS. I am using Chrome

Mark VonGyer
Mark VonGyer
21,239 Points

Isaiah do you have any additional CSS that may be overriding that block?

Isaiah Wojciechowski
Isaiah Wojciechowski
3,163 Points

Mark, I don't see any and like I said if i change it to a:focus it works as expected

Mark VonGyer
Mark VonGyer
21,239 Points

I suggest using *:focus instead of just :focus