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 trialMark Moran
4,207 PointsUnable to solve task 2 of 2 in Stage 3: Advanced Selectors. =(
I tried several different solutions and feel like this one is correct:
:target([id*='#']) {
background-color: tomato;
}
But it doesn't seem to be working ... Any help?
1 Answer
Ron McCranie
7,837 PointsYou're over thinking it a little. The :target
pseudo element will select any element on the page who's id matches the hash value in the url.
:target {
background: tomato;
}
Mark Moran
4,207 PointsMark Moran
4,207 PointsThanks Ron. I guess the problem is that I don't understand what a "hash value" is. Can you shed some light on that? I thought it was referring to a value that is the hash/pound symbol?
Hugo Paz
15,622 PointsHugo Paz
15,622 PointsHi Mark,
The hash value refers to the value inside an Anchor tag like this:
<li><a href="#s1">Section 1</a></li>
In this case the value is s1 which is the id of the following div:
Once you click on the link the div background will turn to tomato colour, using Ron code above.
Mark Moran
4,207 PointsMark Moran
4,207 PointsSo, :target will select anything on the page within the quote marks in an <a> tag? And on a page with multiple <a> tags it selects all of them? Just want to make sure I understand. Thanks so much for your help. :-)
Hugo Paz
15,622 PointsHugo Paz
15,622 PointsThe :target pseudo selector matches when the hash in the URL and the id of an element are the same.
If you have this css:
And this HTML
If you clink the first link, it will take you to the section1 on the page and will turn that div background light blue.
If you click the second link, it will take you to the section2, turn that div background light blue while the s1 div background color will turn back to the default one.
Mark Moran
4,207 PointsMark Moran
4,207 PointsAh! I get it now. Thanks so much for your help. Yay for lightbulbs over the head. :-)