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 trialZach Handler
Web Development Techdegree Student 5,332 PointsHow do you apply a transition to only specific elements?
In the code below (which was written in this lesson), I don't want the transition to be applied to the second css rule. How can I re-write this so the transition is applied only to the last two rules?
.slide .photo-overlay, .slide img { transition: transform 600ms ease-out; }
.slide .photo-overlay { transform: translateX(-100%); }
.slide:hover .photo-overlay { transform: translateX(0); }
.slide:hover img { transform: translateX(100%); }
1 Answer
Steven Parker
231,269 PointsIt's the same elements, they're just in different states (like "hover"). The solution is to re-write the selectors for the transition so they include the state:
.slide:hover .photo-overlay,
.slide:hover img { transition: transform 600ms ease-out; }