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 trialLearning coding
Front End Web Development Techdegree Student 9,937 PointsIs it possible that a picture rotates half up when you hover over it and that you see another img appearing behind it?
This is what I thought about when I heard Guil saying at 0.43 (Changing the Transform Position with transform-origin) that he made a grey background in the picture.
Is it possible to replace the grey background with an img so that img will appear after hovering over the initial img?
2 Answers
Jaspreet Singh
5,207 Pointsyes it is possible you have to add 2nd img using absolute position and hide it behind the first image
lonedo
24,500 PointsIndeed it is, One way this can be achieved is by containing your img inside a div, then change the div's background to the desired hidden image. If the background is poking out, you could either match div size to img, or perhaps hide the background and reveal on hover.
<div class="frame">
<img src="img/photos/1.jpg">
</div>
.frame {
background-image: url("../img/photos/2.jpg");
background-size: cover;
background-repeat: no-repeat;
}
.frame, .frame img {
height: 250px;
}
.frame img {
transition: transform .5s;
transform-origin: 50% 0;
}
.frame:hover img {
transform: rotate(-180deg);
}