Created
August 1, 2013 14:04
-
-
Save Hexrays/6131666 to your computer and use it in GitHub Desktop.
A CodePen by Jeffd. 3D Rotating Cube - based on this tutorial http://davidwalsh.name/css-cube?utm_source=html5weekly&utm_medium=email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="wrap"> | |
<div class="cube"> | |
<div class="front">front</div> | |
<div class="back">back</div> | |
<div class="top">top</div> | |
<div class="bottom">bottom</div> | |
<div class="left">left</div> | |
<div class="right">right</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
width: 100%; | |
/*border: 1px solid orange;*/ | |
} | |
.wrap { | |
margin: 0 100px; | |
perspective: 800px; | |
perspective-origin: 50% 100px; | |
/*border: 1px solid red;*/ | |
width: 100%; | |
height: 300px; | |
margin: 0; | |
margin-top: 50px; | |
} | |
.cube { | |
position: relative; | |
margin: 0 auto; | |
width: 200px; | |
transform-style: preserve-3d; | |
animation: spin 4s infinite linear; | |
/*border: 1px solid blue;*/ | |
} | |
.cube div { | |
position: absolute; | |
width: 200px; | |
height: 200px; | |
background-color: rgba(42,222,38,0.25); | |
/*border: 1px solid green;*/ | |
box-shadow: inset 4px 4px 30px rgba(0,0,0,0.25); | |
text-align: center; | |
font-family: sans-serif; | |
line-height: 200px; | |
transition: background-color 1s ease; | |
} | |
.cube div:hover { | |
background-color: rgba(255,0,38,0.25); | |
} | |
.back { | |
transform: translateZ(-100px) rotateY(180deg); | |
} | |
.right { | |
transform: rotateY(-270deg) translateX(100px); | |
transform-origin: top right; | |
} | |
.left { | |
transform: rotateY(270deg) translateX(-100px); | |
transform-origin: center left; | |
} | |
.top { | |
transform: rotateX(-90deg) translateY(-100px); | |
transform-origin: top center; | |
} | |
.bottom { | |
transform: rotateX(90deg) translateY(100px); | |
transform-origin: bottom center; | |
} | |
.front { | |
transform: translateZ(100px); | |
} | |
@keyframes spin { | |
from { transform: rotateY(0) } | |
to { transform: rotateY(360deg) } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment