Skip to content

Instantly share code, notes, and snippets.

@neilberget
Created August 18, 2012 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilberget/3389130 to your computer and use it in GitHub Desktop.
Save neilberget/3389130 to your computer and use it in GitHub Desktop.
3d flip card effect with CSS
<div class="container">
<div class="flipcard">
<figure class="front">
Front of Card
</figure>
<figure class="back">
Back of Card
</figure>
</div>
</div>
.container {
position: relative;
-webkit-perspective: 800px;
-moz-perspective: 800px;
perspective: 800px;
}
.flipcard {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: -webkit-transform 1s;
-moz-transform-style: preserve-3d;
-moz-transition: -moz-transform 1s;
}
.flipcard figure {
width: 100%;
-webkit-backface-visibility:hidden;
-moz-backface-visibility:hidden;
}
.flipcard .front {
-webkit-transition: -webkit-transform 500ms;
-moz-transition: -moz-transform 500ms;
}
.flipcard.flipped .front {
-webkit-transform: rotate3d(0,1,0,-180deg);
-moz-transform: rotate3d(0,1,0,-180deg);
}
.flipcard .back {
position: absolute;
top: 0;
left: 0;
-webkit-transition: -webkit-transform 500ms;
-webkit-transform: rotate3d(0,1,0,180deg);
-moz-transition: -moz-transform 500ms;
-moz-transform: rotate3d(0,1,0,180deg);
}
.flipcard.flipped .back {
-webkit-transform: rotate3d(0,1,0,0);
-moz-transform: rotate3d(0,1,0,0);
}
@neilberget
Copy link
Author

Just have to add a class to the .flipcard div of "flipped" when you want the back to come into view and remove it to go back to the front.

Mess with the perspective px amount to change how near or close the flip appears to be happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment