Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Transitions and Transforms Getting Started with CSS Transforms Changing the Transform Position with transform-origin

Learning coding
seal-mask
.a{fill-rule:evenodd;}techdegree
Learning coding
Front End Web Development Techdegree Student 9,937 Points

Is 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

yes it is possible you have to add 2nd img using absolute position and hide it behind the first image

Indeed 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);
       }

Live Example