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 Foundations Advanced Selectors Additional Pseudo-Classes

Lea Pritchard
Lea Pritchard
7,040 Points

Can someone explain "...targets an element only if its ID matches the hash in a URL."?

I think I just don't understand the question...

3 Answers

The question is asking what the name of the selector used to target elements. Sorry if this just gives you the answer but...

I believe it is talking about the :target pseudo selector. Here is the link to the W3 schools explanation http://www.w3schools.com/cssref/sel_target.asp

Ah I must be thinking of something else then.

You're correct here.

Felix Yakubov
Felix Yakubov
17,475 Points

If you have the project open before you you'll see that there are three links and three paragraphs, each one with a link with a specific ID. The link anchors target the paragraphs: <a href="#s1">link</a> <p id="s1"> The link matches to the ID. And the :target does the same thing. Any selector you'll add to the :target will apply when you press the link.

Hope this wasn't confusing... check this out too: http://css-tricks.com/on-target/

Create a new rule using the selector that targets an element only if its ID matches the hash in a URL. Set the background color to tomato.

You have been asked to select the element with IDs that matches #.

In CSS, # represents IDs. So you should select elements with IDs. Next thing, you will have to see is what elements will create IDs part of URLs. Oblivious answer will be anchor elements href attribute.

But anchor element's href attribute holds location of other elements. So I did choose IDs s1 and s2. Check the code snippet below.

:root{
  background-color: lightblue; 
}

#s1, #s2{
  background-color: tomato; 
}