Created
August 8, 2012 16:08
-
-
Save yukulele/3296265 to your computer and use it in GitHub Desktop.
3D cube
This file contains 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
/** | |
* 3D cube | |
*/ | |
html,body{ | |
overflow:hidden; | |
} | |
#cube { | |
position:relative; | |
background:#ccc; | |
perspective: 200px; | |
width:300px; | |
height:300px; | |
margin:0 auto; | |
} | |
input:checked ~ #cube>section>section:after, | |
input:checked ~ #cube>section>section{ | |
backface-visibility: hidden; | |
} | |
#cube > section { | |
position:absolute; | |
left:50%; | |
top:50%; | |
display: block; | |
transform: rotateX(-30deg) rotateY(45deg); | |
transform-style: preserve-3d; | |
transition:transform 1s; | |
} | |
#cube > section:after { | |
content:''; | |
display:block; | |
width:4px; | |
height:4px; | |
background:red; | |
position:absolute; | |
top:-2px; | |
left:-2px; | |
transform-origin: center; | |
} | |
#cube:hover > section{ | |
transform: rotateX(30deg) rotateY(360deg); | |
} | |
#cube > section > section { | |
position:absolute; | |
top:-50px; | |
left:-50px; | |
width: 100px; | |
height: 100px; | |
box-sizing:border-box; | |
border: 10px solid rgba(255,255,255,.7); | |
border-radius:25px; | |
background:rgba(255,0,0,.1); | |
color: white; | |
font-size: 70px; | |
text-align: center; | |
transform-origin: center; | |
transform-style: preserve-3d; | |
text-shadow:0 0 5px red | |
} | |
#cube > section > section:after { | |
content:''; | |
position:absolute; | |
top:0; | |
left:0; | |
right:0; | |
bottom:0; | |
background: hsla(220,20%,50%,.5); | |
transform:translatez(-10px); | |
border-radius:10px; | |
box-shadow:0 0 10px green; | |
} | |
#cube > section > section:nth-child(1) { | |
transform: rotatey(0deg) translateZ(50px); | |
} | |
#cube > section > section:nth-child(2) { | |
transform: rotatey(90deg) translateZ(50px); | |
} | |
#cube > section > section:nth-child(3) { | |
transform: rotatex(-90deg) translateZ(50px); | |
} | |
#cube > section > section:nth-child(4) { | |
transform: rotatex(90deg) translateZ(50px); | |
} | |
#cube > section > section:nth-child(5) { | |
transform: rotatey(-90deg) translateZ(50px); | |
} | |
#cube > section > section:nth-child(6) { | |
transform: rotatey(180deg) translateZ(50px); | |
} | |
This file contains 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
<input type="checkbox" id="cb"> <label for='cb'> hide backface</label> | |
<div id="cube"> | |
<section> | |
<section>1</section> | |
<section>2</section> | |
<section>3</section> | |
<section>4</section> | |
<section>5</section> | |
<section>6</section> | |
</section> | |
</div> | |
This file contains 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
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment