文章数量
36
访客量
4952
访问量
9817

css特效之旋转立方体

阅读量:781
更新时间:2023-02-02 21:36:01

效果预览:效果预览
源码下载:关注公众号【RMRF】,回复【css4】可获取源码

一、HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒子</title>
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>
    <div class="box">
        <div class="face_1">Hello World</div>
        <div class="face_2"></div>
        <div class="face_3"></div>
        <div class="face_4"></div>
        <div class="face_5"></div>
        <div class="face_6"></div>
        <div class="face_shadow"></div>
    </div>
</body>
</html>

二、CSS样式

body {
    padding: 0px;
    margin: 0px;
}

.box {
    position: relative;
    width: 500px;
    height: 500px;
    margin: 50px auto;
    transform-style: preserve-3d;
    animation: start 5s linear infinite;
}

.box div {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    height: 200px;
    width: 200px;
    border: 1px solid #333;
    opacity: 0.6;
    background: #ab8b12;
}

.face_1 {
    transform: translateZ(100px);
    font-size: 30px;
    line-height: 200px;
    color: #daf468;
    font-weight: bold;
    text-align: center;
    text-shadow: 3px 3px 3px #999;
}

.face_2 {
    transform: rotateY(90deg) translateZ(100px)
}

.face_3 {
    transform: rotateX(-90deg) translateZ(100px)
}

.face_4 {
    transform: translateZ(-100px)
}

.face_5 {
    transform: rotateY(-90deg) translateZ(100px)
}

.face_6 {
    transform: rotateX(90deg) translateZ(100px)
}

.face_shadow {
    filter: blur(40px);
    transform: rotateX(-90deg) translateZ(150px);
    border: none !important;
    background: #999 !important;
}

@keyframes start {
    0% {
        transform: rotateX(-10deg) rotateY(45deg) rotateZ(0deg);
    }

    100% {
        transform: rotateX(-10deg) rotateY(405deg) rotateZ(0deg);
    }
}