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

Janina Alvarez
PLUS
Janina Alvarez
Courses Plus Student 5,192 Points

"Eat" Animation -- Why is the animation being applied to the "monster" class?

From what I understand, #eat:target should be applying the animation/:target styling to the link element whose id is "eat". Instead, the animation is getting applied to the "monster" div. Why is that the case?

3 Answers

Janina Alvarez
PLUS
Janina Alvarez
Courses Plus Student 5,192 Points

Hey Travis Alstrand , my bad , I thought I asked this question from the lesson directly ๐Ÿ˜…

It's from the :target and :root element lesson in CSS Selectors course: https://teamtreehouse.com/library/css-selectors/root-and-target

This is the codepen I'm referring to: https://codepen.io/Guilh/pen/QwvxOp

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Data Analysis Techdegree Graduate 47,831 Points

Well you are correct, it is being applied to the div with the class of monster, but this is actually the same div that holds the id of eat.

And as Guil says at 3:03 of the video you shared, when clicking a link, if an element's id matches the href of the link, it will take on the styles defined in the :target selector rule.

I hope this helps clear things up! :smiley:

<div id="eat" class="monster"></div>

<a href="#eat">Eat</a>
<a href="#">Stop Eating</a>
Janina Alvarez
PLUS
Janina Alvarez
Courses Plus Student 5,192 Points

Ahhh that makes sense, thank you!! I got confused because I automatically associated the '#eat' in the CSS with #eat (the href attribute value for the link) in the HTML--- even though # in CSS actually refers to ID in html ๐Ÿ˜…

Thank you for clearing that up!