效果:
有空再把它做成真正可以扭的魔方
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3d魔方</title>
<style>
.parent {
width: 700px;
height: 700px;
margin: 0 auto;
position: relative;
perspective: 500px;
}
.big {
position: absolute;
width: 300px;
height: 300px;
transform-style: preserve-3d;
/*animation: rotate 3s linear infinite;*/
}
.bigBig {
position: absolute;
width: 100%;
height: 100%;
transform-style: preserve-3d;
animation: rotate 10s linear infinite;
}
.color {
position: absolute;
top: 300px;
left: 300px;
width: 100px;
height: 100px;
transform-style: preserve-3d;
}
.color div {
position: absolute;
width: 100%;
height: 100%;
border-radius: 8px;
border: white solid 1px;
opacity: 0.7;
}
.color div:nth-child(1){
transform-origin: left;
background-color: green;
transform: rotateY(-90deg);
}
.color div:nth-child(2){
transform-origin: right;
background-color: blue;
transform: rotateY(90deg);
}
.color div:nth-child(3){
background-color: red;
transform-origin: top;
transform: rotateX(90deg);
}
.color div:nth-child(4){
background-color: pink;
transform-origin: bottom;
transform: rotateX(-90deg);
}
.color div:nth-child(5){
background-color: white;
transform: translateZ(100px);
}
.color div:nth-child(6){
background-color: yellow;
}
.big .color:nth-child(1){
}
.big .color:nth-child(2){
transform: translateX(-100px);
}
.big .color:nth-child(3){
/*animation: rotate 3s linear infinite;*/
transform: translateX(100px);
}
.big .color:nth-child(4){
transform: translateY(-100px);
}
.big .color:nth-child(5){
transform: translateY(100px);
}
.big .color:nth-child(6){
transform: translate3d(100px,100px,0px);
}
.big .color:nth-child(7){
transform: translate3d(100px,-100px,0px);
}
.big .color:nth-child(8){
transform: translate3d(-100px,100px,0px);
}
.big .color:nth-child(9){
transform: translate3d(-100px,-100px,0px);
}
.bigBig .big:nth-child(1){
transform: translateZ(-150px);
transition: all 3s;
}
.bigBig .big:nth-child(2){
transform: translateZ(-50px);
}
.bigBig .big:nth-child(3){
/*animation: rotate 3s linear infinite;*/
transform: translateZ(50px);
}
@keyframes rotate {
0%{
transform: rotateX(0deg);
}
100% {
transform: rotateX(360deg);
}
}
</style>
</head>
<body>
<div class="parent">
<section class="bigBig">
<section class="big">
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</section>
<section class="big">
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</section>
<section class="big">
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section class="color">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</section>
</section>
</div>
</body>
</html>