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

Sereta Baldwin
Sereta Baldwin
6,183 Points

Right at the end of the video you can see that the 'color: white' bit got ignored after he deleted 'a'. Wondering why.

I'm an absolute noob at this stuff, so if someone answers this, please do so with this in mind! Thanks.
Just to clarify, this is at the end of the video when he is showing the ':focus' pseudo-class. When it was written 'a:focus' the text showed up as white with an orange background, but once he deleted the 'a' in the beginning then the orange background still showed up, but the text stayed lightblue. Just wondering why! Thanks again if anyone takes the time to clear up my doubts :)

1 Answer

Steven Parker
Steven Parker
230,248 Points

The selector "a:focus" means "an anchor element (link) that has focus", but just ":focus" by itself means "any element that has focus". So there won't be any change to "a" elements, but now the rule will cover other input elements (if there are any) when they have focus.

The other thing that happens is the rule now has lower specificity. A rule that targets both a tag and a class is considered more important that one that targets only a class. So while this rule previously superseded the color set by other CSS rules, without the "a" it does not.

For more details, see the MDN page on Specificity.