Tuesday, 20 May 2014

CSS3 Backface

Hide the backside of a rotated div element by hovering over the card below.

<html lang="en">
<head>
<meta charset="UTF-8">
<style>
#container {
position: relative;
margin: 10px auto;
width: 120px;
height: 180px;
z-index: 1;
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
perspective: 1000px;
}
#card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#container:hover #card, #container.hover_effect #card {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
}
.face.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div id="container" class="hover">
<div id="card">
<div class="front face">
<img src="front.png"/>
</div>
<div class="back face">
<img src="back.png"/>
</div>
</div>
</div>
</body>
</html>

No comments:

Post a Comment