纯CSS实现3D立方体相册效果

本文介绍了一个使用HTML和CSS实现的3D立方体相册动画,通过transform和animation属性,创建了一个旋转的3D立方体,立方体的每个面都展示了图片,并且在鼠标悬停时,立方体的面会进一步伸展,提供了丰富的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>3D立方体相册</title>

    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            width: 100%;
            height: 100%;
            background: linear-gradient(yellow 0%, black 100%);
        }

        #react {
            width: 200px;
            height: 200px;
            margin: 200px auto;
            transform-style: preserve-3d;
            animation: rotate 20s infinite;
            animation-timing-function: linear;
        }

        #react div {
            position: absolute;
            transition: all .4s;
        }

        div .out_pic {
            width: 200px;
            height: 200px;
            opacity: 0.9;
        }

        div .in_pic {
            width: 100px;
            height: 100px;
        }

        #react span {
            display: block;
            position: absolute;
            width: 100px;
            height: 100px;
            top: 50px;
            left: 50px;
        }

        @keyframes rotate {
            from {
                transform: rotateX(0deg) rotateY(0deg);
            }

            to {
                transform: rotateX(360deg) rotateY(360deg);
            }
        }

        .out_frount {
            transform: translateZ(100px);
        }

        .out_back {
            transform: translateZ(-100px);
        }

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

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

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

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

        .in_frount {
            transform: translateZ(50px);
        }

        .in_back {
            transform: translateZ(-50px);
        }

        .in_left {
            transform: rotateY(90deg) translateZ(50px);
        }

        .in_right {
            transform: rotateY(-90deg) translateZ(50px);
        }

        .in_top {
            transform: rotateX(90deg) translateZ(50px);
        }

        .in_bottom {
            transform: rotateX(-90deg) translateZ(50px);
        }

        #react:hover .out_frount {
            transform: translateZ(200px);
        }

        #react:hover .out_back {
            transform: translateZ(-200px);
        }

        #react:hover .out_left {
            transform: rotateY(90deg) translateZ(200px);
        }

        #react:hover .out_right {
            transform: rotateY(-90deg) translateZ(200px);
        }

        #react:hover .out_top {
            transform: rotateX(90deg) translateZ(200px);
        }

        #react:hover .out_bottom {
            transform: rotateX(-90deg) translateZ(200px);
        }
    </style>

</head>

<body>
    <div id="react">
        <div class="out_frount">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <div class="out_back">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <div class="out_left">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <div class="out_right">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <div class="out_top">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <div class="out_bottom">
            <img src="./img/yoga.png" class="out_pic">
        </div>
        <span class="in_frount">
            <img src="./img/yoga.png" class="in_pic">
        </span>
        <span class="in_back">
            <img src="./img/yoga.png" class="in_pic">
        </span>
        <span class="in_left">
            <img src="./img/yoga.png" class="in_pic">
        </span>
        <span class="in_right">
            <img src="./img/yoga.png" class="in_pic">
        </span>
        <span class="in_top">
            <img src="./img/yoga.png" class="in_pic">
        </span>
        <span class="in_bottom">
            <img src="./img/yoga.png" class="in_pic">
        </span>
    </div>
</body>

</html>

转自:https://www.cnblogs.com/xmoomoo/p/5749160.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值