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 trialJanina Alvarez
8,083 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
8,083 PointsHey 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
Data Analysis Techdegree Graduate 49,443 PointsWell 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!
<div id="eat" class="monster"></div>
<a href="#eat">Eat</a>
<a href="#">Stop Eating</a>
Janina Alvarez
8,083 PointsAhhh 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!
Travis Alstrand
Data Analysis Techdegree Graduate 49,443 PointsVery understandable! You're very welcome, I'm glad it cleared things up for you
Travis Alstrand
Data Analysis Techdegree Graduate 49,443 PointsTravis Alstrand
Data Analysis Techdegree Graduate 49,443 PointsHey Janina Alvarez !
I'm not familiar with what video or course this is in reference too. Could you provide a link to the video you're on please?