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

Frederik Delfosse
Frederik Delfosse
1,874 Points

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

How do you do this? I am doing something wrong but do not know what...

:target([id="#"]) { background-color: tomato; }

4 Answers

Hmmm, I am wondering why would you ever use hash tag as ID of element. This is used just for testing purposes but not in real life projects.

However, if you want to target all the elements, that contain # + some other characters (id="#example" or id="example#" or id="exa#ple" or just id="#") you should use following selector

*[id^="#"] {

 background-color: tomato; /* or any different styles you want to apply */

}

Let me know if it has helped you.

Frank

Frederik Delfosse
Frederik Delfosse
1,874 Points

I am really sorry but that did not work.

This is the Question: 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.

Frederik Delfosse
Frederik Delfosse
1,874 Points

Apparaently this was the correct answer

:target { background-color: #EA2E49; }

Łukasz Czuliński
Łukasz Czuliński
8,646 Points

I had to Google this to find out the answer. I don't understand why your first one (and mine) didn't work. Can someone enlighten us?