transform属性做出一个3d旋转的正方体
下午试着用css中的transform属性做了一个3d可旋转的正方体,把各个面放上图片的,顺便加上box-shadow,使之具有荧光的效果,加完图片后的最终效果如下图
<!DOCTYPE html>
<html>
<head>
<title>3d正方体旋转</title>
<style type="text/css">
body{background: #000;}
#box{
width: 300px;height: 300px;
border-radius: 30px;
position: relative;
transform-style:preserve-3d;
left: 300px;top: 200px;
transform:rotateX(-45deg) rotateY(-45deg);
animation: rotate linear 20s infinite;
}
@keyframes rotate{
0%{transform:rotateX(-45deg) rotateY(-45deg) rotateZ(-45deg); }
20%{transform:rotateX(-90deg) rotateY(-90deg) rotateZ(45deg); }
40%{transform:rotateX(-135deg) rotateY(-125deg) rotateZ(-135deg);}
60%{transform:rotateX(-160deg) rotateY(90deg) rotateZ(-180deg);}
80%{transform:rotateX(-60deg) rotateY(-25deg) rotateZ(-105deg);}
100%{transform:rotateX(50deg) rotateY(-45deg) rotateZ(-45deg);}
}
#box div{
width: 300px;
height: 300px;
border-radius: 30%;
overflow: hidden;
position: absolute;
left: 0;top: 0;
font-size: 160px;
color: white;
line-height: 300px;
text-align: center;
opacity: 0.9;
box-shadow: 0 0 100px blue;}
img{width: 300px;}
.div1{transform: translateZ(150px);}
.div2{transform: rotateY(-90deg) translateZ(150px);}
.div3{transform: rotateX(90deg) translateZ(-150px);}
.div4{transform: rotateY(90deg) translateZ(150px);}
.div5{transform: rotateX(-90deg) translateZ(-150px);}
.div6{transform:translateZ(-150px);}
</style>
</head>
<body>
<div id="box">
<div class="div1"><img src="img/1.jpg"></div>
<div class="div2"><img src="img/2.jpg"></div>
<div class="div3"><img src="img/5.jpg"></div>
<div class="div4"><img src="img/6.jpg"></div>
<div class="div5"><img src="img/7.jpg"></div>
<div class="div6"><img src="img/8.jpg"></div>
</div>
</body>
</html>