Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Pseudo-class help [Resolved]

Hey guys, I hope you are great.

I have a quick question. I just took the 'More Pseudo-classes' challenge and even when I got this answer correct I feel that I'm missing something.

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 the HEX value EA2E49.

This is the code I have used:

:target {
    background-color: #EA2E49;
}

Thanks!

11 Answers

Jason Hess
Jason Hess
4,789 Points

The question is bit of a trick question If you read the question carefully, it's actually very simple, they do try to trick you up in throwing in the whole "url" thing.

All they are asking is "Create a new selector(the psuedo-class you just watched in the video) that "targets" an element that has a # "hash" in its url. and set the background color to whatever HEX value. They are not telling you to target the hash, but just to create the selector that would target the element. Try not to beat yourself up over these questions. You're just going to get frustrated and not sign back in for a few weeks. The forum is there for you to get assistance.

Muhammad Sajid
Muhammad Sajid
6,088 Points

div:target{ background: #EA2E49; }

Get the "jsFiddle" example perfectly. Don't know how to pass this step of the challenge. Also, able to make it work in CodePen....don't know what's up with that.

/* Just to note the above concern was never answered */

I was able to figure this out though; after I left it alone for 2 weeks and came back. The question should be worded like this.

"Create a new selector that "targets" an element that has a # "hash" in its url. and set the background color to whatever HEX value".....This doesn't give me everything, but I can see that I need to find a url that has a # in it. From there I can see if what I'm looking for is a Class or an ID that references said url.

It's confusing because it sounds like you're asking me to find an ID with a # in it. After reading it a million times I figured out you wanted me to match an ID (which is unknown) to the "section" it references on the page.

samiff
samiff
31,206 Points

I've never used this myself, but the way I understand it is that the CSS rule using :target will apply or "match" whenever the hash in a URL matches a corresponding ID value of an element on the page.

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hi Ibrahim Rodrí­guez,

Do you feel as if you're missing something from the code challenge, or something (further instruction) from the video lesson?

Thanks!

Hi Guil!

I feel I'm missing more lines in the code I submitted. I don't see any ID matching the hash in a url on my code. The video is perfect maybe is just that I didn't understand the challenge very well. Maybe I need something before ":target", but again, I'm not sure.

Thanks!

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Ibrahim Rodrí­guez ,

You can prepend it with an element or class name if you need to. You can also use it in a descendant selector to target specific areas of the page.

Take a look at this jsFiddle example.

Hope this helps :)

Awesome! Thanks so much for your help Guil and Sam!

Frederik Delfosse
Frederik Delfosse
1,874 Points

Ow my god. The result was so simple :/

Joseph: Refresh the page and do the challenge again. The first rule you tried will work. I believe the code on the site was just having an issue.

I am having trouble with this too. The question is now: "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."

So far I've tried:

:target {
       background-color: tomato;
         }

and

div:target {
       background-color: tomato;
         }

I got to the same question and solved it with the first one you mentioned:

:target { background-color: tomato; }

Did it for me.