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 trialMolly Morby
2,398 PointsAdding a new rule
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.
2 Answers
Blake Lieberman
23,772 Points*:target
This is a selector that does exactly what you are looking for.
"Style a Specific Target :target
Selector URL Div
*:target
http://example.com/about.html#thebox
<div id=βtheboxβ>stuff in here styled</div>
This oneβs pretty cool. If somebody accesses your site using http://example.com/about.html#thebox, :target will style the div with ID of thebox.
This could definitely be used when you are trying to link to a specific comment on a page and want to highlight it." - scotch.io
http://scotch.io/bar-talk/css-selectors-you-might-not-know-about#target-pseudo-class
Adam Little
6,735 PointsIf I understand you correctly, first you need to get the name ID in your HTML, then use the following code. Replace "(name of your id)" with the ID name.
#(name of your id) {
color: tomato;
}
Shawn Flanigan
Courses Plus Student 15,815 PointsShawn Flanigan
Courses Plus Student 15,815 PointsNice one, Blake. This is one of those pseudo selectors I never use and 100% forgot existed. Had to delete my answer in embarrassment.