$boxwidth: 200px;
$boxheight: 200px;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
h1, h2, h3, p {
margin: 0 0 1em;
}
.wrap:after {
content: "";
display: block;
clear: both;
}
.box-rotate-wrap {
float: left;
margin: 0 30px 30px 0;
perspective: 1000px;
}
.box, .box > div {
width: $boxwidth;
height: $boxheight;
}
.box-rotate {
position: relative;
transition: all 0.8s ease;
transform-style: preserve-3d;
transform: translate3d(0, 0, -$boxheight/2);
}
.box-rotate > div {
position: absolute;
top: 0;
left: 0;
z-index: 1;
background: #fff;
padding: 20px;
overflow: auto;
}
.box-rotate img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.box-rotate .front {
background: red;
z-index: 2;
transform: rotate3d(0, 1, 0, 0deg) translate3d(0, 0, $boxwidth/2);
}
.box-rotate .back {
background: orange;
transform: rotate3d(0, 1, 0, 180deg) rotate(180deg) translate3d(0, 0, $boxwidth/2);
}
.box-rotate .top {
background: purple;
height: $boxwidth;
transform: rotate3d(1, 0, 0, 90deg) translate3d(0, 0, $boxwidth/2);
}
.box-rotate .bottom {
background: blue;
height: $boxwidth;
transform: rotate3d(1, 0, 0, -90deg) translate3d(0, 0, $boxheight - $boxwidth/2);
}
.box-rotate .left {
background: yellow;
transform: rotate3d(0, 1, 0, -90deg) translate3d(0, 0, $boxwidth/2);
}
.box-rotate .right {
background: green;
transform: rotate3d(0, 1, 0, 90deg) translate3d(0, 0, $boxwidth/2);
}
.box-rotate-top:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(1, 0, 0, -90deg);
}
.box-rotate-bottom:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(1, 0, 0, 90deg);
}
.box-rotate-left:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(0, 1, 0, 90deg);
}
.box-rotate-right:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(0, 1, 0, -90deg);
}
.box-rotate-back:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(1, 0, 0, -180deg);
}
.box-rotate-gyro .back {
width: $boxheight;
height: $boxwidth;
transform: rotate3d(0, 1, 0, 180deg) rotate(90deg) translate3d($boxheight/2 - $boxwidth/2, -$boxheight/2 + $boxwidth/2, $boxwidth/2);
}
.box-rotate-gyro:hover {
transform: translate3d(0, 0, -$boxwidth/2) rotate3d(1, 1, 0, -180deg);
}
.box.box-blend div {
background: #fff;
box-shadow: 0 0 1px rgba(0,0,0,.8);
}