CSS3:旋转正方体
Posted yujian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS3:旋转正方体相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>旋转正方体</title>
<style>
html {
background: linear-gradient(#9ed128 0%, #358b98 80%);
height: 1000px;
opacity: 0.8;
}
.wrapper {
margin-top: 200px;
perspective: 1000px;
}
.cube {
height: 200px;
width: 200px;
position: relative;
margin: auto;
transform-style: preserve-3d;
-webkit-animation: rotate 15s infinite;
-o-animation: rotate 15s infinite;
animation: rotate 15s infinite 2s;
}
@keyframes rotate {
from {
transform: rotateY(0deg) rotateX(0deg);
}
to {
transform: rotateY(360deg) rotateX(360deg);
}
}
.cube>div {
height: 100%;
width: 100%;
opacity: 0.6;
position: absolute;
text-align: center;
background: pink;
color: #fff;
line-height: 200px;
font-size: 30px;
}
.plane-front {
transform: translateZ(100px);
}
.plane-back {
transform: rotateY(180deg) translateZ(100px);
}
.plane-left {
transform: rotateY(270deg) translateZ(100px);
}
.plane-right {
transform: rotateY(90deg) translateZ(100px);
}
.plane-top {
transform: rotateX(90deg) translateZ(100px);
}
.plane-bottom {
transform: rotateX(270deg) translateZ(100px);
}
.cube:hover .plane-front {
transform: translateZ(200px);
}
.cube:hover .plane-back {
transform: rotateY(180deg) translateZ(200px);
}
.cube:hover .plane-left {
transform: rotateY(270deg) translateZ(200px);
}
.cube:hover .plane-right {
transform: rotateY(90deg) translateZ(200px);
}
.cube:hover .plane-top {
transform: rotateX(90deg) translateZ(200px);
}
.cube:hover .plane-bottom {
transform: rotateX(270deg) translateZ(200px);
}
</style>
</head>
<body>
<div class="wrapper">
<div class="cube">
<div class="plane-front">前面</div>
<div class="plane-back">后面</div>
<div class="plane-right">右面</div>
<div class="plane-left">左面</div>
<div class="plane-top">上面</div>
<div class="plane-bottom">下面</div>
</div>
</div>
</body>
</html>
以上是关于CSS3:旋转正方体的主要内容,如果未能解决你的问题,请参考以下文章