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

More Pseudo-classes Challenge 2

I'm a bit stuck on challenge 2 for More Pseudo-classes, where you're asked to "create a new rule using a selector that targets a div when a link is clicked, only if its ID matches a link href attribute. Set the background color to the HEX value EA2E49."

So you're using :active if the link is being clicked, but am I overthinking it? I've tried various things for over an hour, and task 3 seems comparatively simple.

I started with: :active { background: #EA2E49; } but am not too sure where to go from here, since everything else I've tried hasn't worked. Any tips would be much appreciated.

17 Answers

Juan David Pena
Juan David Pena
2,145 Points

div:target { background-color: #EA2E49; }

Hi all,

I don't get it, how does: "div:target..."

matches: "...an element only if it's ID matches the hash in a URL"

I thought it will require something like [id="#"].

Regards, T.

Jim Ashley
Jim Ashley
3,935 Points

'Please could you try to help me by restating the question in other words so i can comprehend what is being asked or clarify what i am misunderstanding.'

Could not agree more. If/when the 'Fail' message appears, the ambiguous 'check your selector' message doesn't really clarify things.

Itsa Snake
Itsa Snake
3,852 Points

The question is really poorly worded. It's unnecessarily confusing

in the answer, "div:target { background-color: #EA2E49; }" I feel the part of the question that states, "only if its ID matches a link href attribute", isn't being answered.

Maybe this is a trick part of the question but i feel like the code is missing something. Maybe ":target" covers the link href attribute, and I am misunderstanding "ID matches" part for #id.

Please could you try to help me by restating the question in other words so i can comprehend what is being asked or clarify what i am misunderstanding.

Karina Graj
Karina Graj
1,549 Points

I have exactly the same problem. The challange states: 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.

I have consulted this topic: https://teamtreehouse.com/forum/pseudoclass-help-resolved but unfortunately it didn't help much. Guil gave the example below:

.main :target {
    background-color: tomato;
    color: #FFF;
}

I can see from it that there should be a part of the code preceding the :target class, but I have no idea how to construct it.

:target{ background-color:tomato; } Tried dis one fr d challenge nd it actually wrks :)

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hey Simon,

You're close. The keyword in the code challenge is "target". Which selector in the video made reference to this?

Hope this helps :)

Guil

Hi Guil,

Thanks for your response! I think I dug myself into a hole and then kept going around in circles. It makes sense now, but I'll have another read up just to make sure. Thanks again!

Even I am stuck on this challenge I tried using target but the error says to check the selector used in my CSS. Here is my CSS

:root { background-color:#BDD4DE; } :target { background-color:#EASE49; }

Another agree.

Here's another agree.

Vinay Kumar Reddy Yerram
Vinay Kumar Reddy Yerram
3,698 Points

This challenge is very poorly worded and it's really confusing.....hope you can reframe the question properly....

Matt Bowlby
Matt Bowlby
8,806 Points

I am also seriously stuck on this question. My thought was that it would be something like:

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