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 trialSimon Brown
2,493 PointsMore 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
2,145 Pointsdiv:target { background-color: #EA2E49; }
nnuxiragwh
10,345 PointsHi 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
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
3,852 PointsThe question is really poorly worded. It's unnecessarily confusing
Daniel Cudney
4,176 Pointsin 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
1,549 PointsI 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.
Vinyasha V
3,918 Points:target{ background-color:tomato; } Tried dis one fr d challenge nd it actually wrks :)
Guil Hernandez
Treehouse TeacherHey 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
Simon Brown
2,493 PointsHi 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!
Guil Hernandez
Treehouse TeacherAny time!
Shantanu Raj
14,900 PointsEven 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; }
Chris Coy
2,199 Points^^ Agreed
Colin Marshall
32,861 PointsAlso agree.
Jonathan Kim
2,726 PointsAnother agree.
evaconnors
9,198 PointsHere's another agree.
Vinay Kumar Reddy Yerram
3,698 PointsThis challenge is very poorly worded and it's really confusing.....hope you can reframe the question properly....
Matt Bowlby
8,806 PointsI am also seriously stuck on this question. My thought was that it would be something like:
:target([id="#"]) { backgorund-color: tomato; }