Objectives and outcomes

In this tutorial we are going to learn about transformation in CSS3 and using perspective and transform kit in CSS. We can see as we hover on the image below, the image get rotated by some angle and another image appears but the intresting thing to know is there is only a single image and two div which alternatively hide and show themselves.

HTML and CSS code for the above example is given below:

CSS stylesheet:


/* How pronounced should the 3D effects be */
perspective: 800px;
-webkit-perspective: 800px;

background: radial-gradient(#e0e0e0, #aaa);
margin:0 auto;


/* Enable 3D transforms */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;

/* We are using two separate divs for the front and back of the
phone. This will hide the divs when they are flipped, so that the
opposite side can be seen:  */

backface-visibility: hidden;
-webkit-backface-visibility: hidden;


margin:-166px 0 0 -100px;

background:url(img/iphone.jpg) no-repeat left center;

/* Animate the transitions */


/* The back side is flipped 180 deg by default */

background-position:right center;

.container1:hover .iphone1{
/* When the container is hovered, flip the front side and hide it .. */

.container1:hover .iphone2{
/* .. at the same time flip the back side into visibility */


HTML code:

<div class="container1">
<div class="iphone1 img-responsive"></div>
<div class="iphone2 img-responsive"></div>

The perspective property defines how many pixels a 3D element is placed from the view. When defining the perspective property for an element, it is the CHILD elements that get the perspective view, NOT the element itself. Note: The perspective property only affects 3D transformed elements!
preserve-3d is a transform-style which specifies that the child element will preserve its 3D position. And in the last the backface-visibility property defines whether or not an element should be visible when not facing the screen. This property is useful when an element is rotated, and you do not want to see its backside.