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

need help

I am not getting right answer to "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."

I tried with below, but both of them not work

a) *:[id="#"] { background-color:tomato }

b) :[id="#"] { background-color:tomato }

Please let me know why is it not working.

6 Answers

Daniel Barreto
PLUS
Daniel Barreto
Courses Plus Student 14,978 Points

So then you'd use the all selector like you suggested,

[id="bar"] for all elements that have an "id" attribute with the value of anything containing the substring "bar".

Otherwise, if you want to select all elements with the exact ID of "bar" you'd just use the standard ID selector of #bar

Hope I've cleared this up for you.

Edit: The asterisk isn't showing because the forums are mistaking it as the beginning of some Markdown. But this should have an asterisk on the second line infront of the selector

Daniel Barreto
PLUS
Daniel Barreto
Courses Plus Student 14,978 Points

You are not using the correct selector. The selector you want is the psuedo-selector :target . The video before this code challenge has a nice example of this.

Thanks ! i got what you are saying. but i was wondering if it works using "contains" (*) pseudoclass. I tried but it didn't work.Any idea on that?

Daniel Barreto
Daniel Barreto
Courses Plus Student 14,978 Points

Well the contains psuedo-selector will search the element with the attribute and check its value if you ask it to.

So,

p[id="foo"]

will search for a paragraph element whose "id" attribute is the exact value of "foo".

In this example,

p[id*="bar"]

the paragraph element whose "id" attribute contains the substring "bar" will be selected.

So is it possible to replace "p" with "" in your eg above( p[id="bar"]). What i mean is that if you mention "p" at the beginning then we are limiting to "p" element. But what if i want to select all elements like say "p", "div" etc which contains "bar" as id. Thanks in advance.

for some reason "star/asterisk " doesn't show up in my post/comments above.Anyway, what i meant above is replacing "p" with asterisk/star.

yes got it now. Thanks