旋转立方体CSS3

旋转立方体

在这里插入图片描述

css3的学习

html部分

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="3dcube.css">
</head>

<body>
    <div class="wrap"></div>
    <div class="wrap">
        <div class="cube">
            <div class="side cube-front">
                <h2>front</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
            <div class="side cube-back">
                <h2>Back</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
            <div class="side cube-left">
                <h2>Left</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
            <div class="side cube-right">
                <h2>Right</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
            <div class="side cube-top">
                <h2>Top</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
            <div class="side cube-bottom">
                <h2>Bottom</h2>
                <p>If you smile upon the world, it will smile upon you</p>
            </div>
        </div>
    </div>


    <div class="wrap"></div>
</body>

</html>

css部分:

* {
    margin: 0;
    padding: 0;
}

body {
    background: linear-gradient(to bottom, #c0392b, #19a085, #2980b9);
}

.wrap {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cube {
    width: 200px;
    height: 200px;
    position: absolute;
    transform-style: preserve-3d;
    transform: rotateY(0deg) rotateX(45deg) rotateZ(-45deg);
    animation: cube 8s linear infinite;
}

.cube .side {
    width: 100%;
    height: 100%;
    position: absolute;
    box-sizing: border-box;
    border: 1px solid #000;
    padding: 10px;
    background-color: #fff;
}

.cube .cube-front {
    transform: rotateY(0deg) translateZ(100px);
}

.cube .cube-back {
    transform: rotateY(180deg) translateZ(100px);
}

.cube .cube-left {
    transform: rotateY(-90deg) translateZ(100px);
}

.cube .cube-right {
    transform: rotateY(90deg) translateZ(100px);
}

.cube .cube-top {
    transform: rotateX(90deg) translateZ(100px);
}

.cube .cube-bottom {
    transform: rotateX(-90deg) translateZ(100px);
}

@keyframes cube {
    from {
        transform: rotateY(0deg) rotateX(-45deg) rotateZ(-45deg);
    }
    to {
        transform: rotateY(360deg) rotateX(-45deg) rotateZ(-45deg);
    }
}

.cube:hover {
    animation-play-state: paused;
}
发布了108 篇原创文章 · 获赞 114 · 访问量 8561

猜你喜欢

转载自blog.csdn.net/weixin_45773503/article/details/104713126
今日推荐