-
-
Save Tahseenm/da33234380e3b40781d586ec1e39c176 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
* { | |
box-sizing: inherit; | |
} | |
::selection { | |
background: #c5f6fa; | |
color: #343a40; | |
} | |
html { | |
box-sizing: border-box; | |
font-size: 16px; | |
background: #FFF; | |
} | |
body { | |
position: relative; | |
min-height: 100vh; | |
margin: 0; | |
font: menu; | |
font-size: 1.125rem; | |
background: #FFF; | |
color: #343a40; | |
} | |
h1 { | |
margin-top: 0; | |
margin-bottom: 1rem; | |
font-size: 2.5rem; | |
} | |
.container { | |
max-width: 680px; | |
padding: 20px; | |
margin-left: auto; | |
margin-right: auto; | |
} | |
.scene { | |
margin-top: calc(50vh - 75px); | |
margin-right: auto; | |
margin-left: auto; | |
width: 150px; | |
height: 150px; | |
perspective: 5000px; | |
transform: scale(1.5); | |
} | |
.cube { | |
position: relative; | |
width: inherit; | |
height: inherit; | |
transition: transform .5s ease-in-out; | |
will-change: transform; | |
transform-style: preserve-3d; | |
transform: rotateX(-20deg) rotateY(-45deg); | |
} | |
.cube:hover { | |
transform: rotateX(-20deg) rotateY(45deg); | |
} | |
.cube-face { | |
width: inherit; | |
height: inherit; | |
position: absolute; | |
background: red; | |
opacity: 0.5; | |
} | |
.cube-face-front { | |
background: yellow; | |
transform: translate3d(0, 0, 75px); | |
} | |
.cube-face-back { | |
background: orange; | |
transform: rotateY(180deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-left { | |
background: green; | |
transform: rotateY(-90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-right { | |
background: magenta; | |
transform: rotateY(90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-top { | |
transform: rotateX(90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-bottom { | |
transform: rotateX(-90deg) translate3d(0, 0, 75px); | |
} | |
</style> | |
</head> | |
<body> | |
<main class="container"> | |
<div class="scene"> | |
<div class="cube"> | |
<div class="cube-face cube-face-front"></div> | |
<div class="cube-face cube-face-back"></div> | |
<div class="cube-face cube-face-left"></div> | |
<div class="cube-face cube-face-right"></div> | |
<div class="cube-face cube-face-top"></div> | |
<div class="cube-face cube-face-bottom"></div> | |
</div> | |
</div> | |
</main> | |
<script id="jsbin-source-css" type="text/css">// MIXINS | |
@mixin center() { | |
margin-right: auto; | |
margin-left: auto; | |
} | |
@mixin cover() { | |
position: absolute; | |
top: 0; right: 0; bottom: 0; left: 0; | |
} | |
// BASE | |
* { | |
box-sizing: inherit; | |
} | |
::selection { | |
background: #c5f6fa; | |
color: #343a40; | |
} | |
html { | |
box-sizing: border-box; | |
font-size: 16px; | |
background: #FFF; | |
} | |
body { | |
position: relative; | |
min-height: 100vh; | |
margin: 0; | |
font: menu; | |
font-size: 1.125rem; | |
background: #FFF; | |
color: #343a40; | |
} | |
h1 { | |
margin-top: 0; | |
margin-bottom: 1rem; | |
font-size: 2.5rem; | |
} | |
// LAYOUT | |
.container { | |
max-width: 680px; | |
padding: 20px; | |
margin-left: auto; | |
margin-right: auto; | |
} | |
// COMPONENTS | |
$size: 150px; | |
.scene { | |
margin-top: calc(50vh - 75px); | |
@include center; | |
width: $size; | |
height: $size; | |
perspective: 5000px; | |
transform: scale(1.5); | |
} | |
.cube { | |
position: relative; | |
width: inherit; | |
height: inherit; | |
transition: transform .5s ease-in-out; | |
will-change: transform; | |
transform-style: preserve-3d; | |
transform: rotateX(-20deg) rotateY(-45deg); | |
&:hover { transform: rotateX(-20deg) rotateY(45deg) } | |
} | |
.cube-face { | |
width: inherit; | |
height: inherit; | |
position: absolute; | |
background: red; | |
opacity: 0.5; | |
} | |
.cube-face-front { | |
background: yellow; | |
transform: translate3d(0, 0, $size/2); | |
} | |
.cube-face-back { | |
background: orange; | |
transform: rotateY(180deg) translate3d(0, 0, $size/2); | |
} | |
.cube-face-left { | |
background: green; | |
transform: rotateY(-90deg) translate3d(0, 0, $size/2); | |
} | |
.cube-face-right { | |
background: magenta; | |
transform: rotateY(90deg) translate3d(0, 0, $size/2); | |
} | |
.cube-face-top { | |
//background: blue; | |
transform: rotateX(90deg) translate3d(0, 0, $size/2); | |
} | |
.cube-face-bottom { | |
//background: red; | |
transform: rotateX(-90deg) translate3d(0, 0, $size/2); | |
} | |
</script> | |
</body> | |
</html> |
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
* { | |
box-sizing: inherit; | |
} | |
::selection { | |
background: #c5f6fa; | |
color: #343a40; | |
} | |
html { | |
box-sizing: border-box; | |
font-size: 16px; | |
background: #FFF; | |
} | |
body { | |
position: relative; | |
min-height: 100vh; | |
margin: 0; | |
font: menu; | |
font-size: 1.125rem; | |
background: #FFF; | |
color: #343a40; | |
} | |
h1 { | |
margin-top: 0; | |
margin-bottom: 1rem; | |
font-size: 2.5rem; | |
} | |
.container { | |
max-width: 680px; | |
padding: 20px; | |
margin-left: auto; | |
margin-right: auto; | |
} | |
.scene { | |
margin-top: calc(50vh - 75px); | |
margin-right: auto; | |
margin-left: auto; | |
width: 150px; | |
height: 150px; | |
perspective: 5000px; | |
transform: scale(1.5); | |
} | |
.cube { | |
position: relative; | |
width: inherit; | |
height: inherit; | |
transition: transform .5s ease-in-out; | |
will-change: transform; | |
transform-style: preserve-3d; | |
transform: rotateX(-20deg) rotateY(-45deg); | |
} | |
.cube:hover { | |
transform: rotateX(-20deg) rotateY(45deg); | |
} | |
.cube-face { | |
width: inherit; | |
height: inherit; | |
position: absolute; | |
background: red; | |
opacity: 0.5; | |
} | |
.cube-face-front { | |
background: yellow; | |
transform: translate3d(0, 0, 75px); | |
} | |
.cube-face-back { | |
background: orange; | |
transform: rotateY(180deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-left { | |
background: green; | |
transform: rotateY(-90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-right { | |
background: magenta; | |
transform: rotateY(90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-top { | |
transform: rotateX(90deg) translate3d(0, 0, 75px); | |
} | |
.cube-face-bottom { | |
transform: rotateX(-90deg) translate3d(0, 0, 75px); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spins on hover using CSS3 Transform