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

Last step of the challenge, what's wrong?

What have I done wrong here?

/* Write your CSS code below */

:root { background-color: lightblue; }

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

2 Answers

Hi Ben,

You only need the :target pseudo class.

:target {
  background: tomato;
}

:target will match any element whose id matches what is in the hash part of the url

Sander de Wijs
PLUS
Sander de Wijs
Courses Plus Student 22,267 Points

I tried this code in the editor

a[href^="#"] {background-color: tomato;}

The links background changes as expected in the preview, but I still get an error. The challenge was '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.'

Sander de Wijs
Sander de Wijs
Courses Plus Student 22,267 Points

Forget what I said. Jason already posted the right answer :)