css3D旋转正方体

这个HTML代码展示了如何使用CSS3实现一个3D立方体的旋转动画,包括六个面(顶部、底部、左侧、右侧、前面和后面)。通过变换属性(translate和rotate),实现了立方体各个面的位置和角度,同时使用了动画关键帧@keyframes实现立方体的连续旋转效果,为网页增添动态视觉体验。

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

<html>
    <head>
        <title>3D立方体</title>
        <style>
            .top {
                background-color: blue;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateY(-100px) rotateX(90deg);
            }
            .bottom {
                background-color: aqua;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateY(100px) rotateX(-90deg);
            }
            .left {
                background-color: blueviolet;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateX(-100px) rotateY(-90deg);
            }
            .right {
                background-color: bisque;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateX(100px) rotateY(90deg);
            }
            .front {
                background-color: pink;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateZ(100px);
            }
            .back {
                background-color: goldenrod;
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0;
                top: 0;
                transform: translateZ(-100px) rotateY(180deg);
            }
            .rotateSquare {
                position: absolute;
                top: 0;
                left: 0;
                bottom: 0;
                right: 0;
                margin: auto;
                transform-style: preserve-3d;
                width: 200px;
                height: 200px;
                transform: rotateY(20deg) rotateX(20deg);
                animation:changeSolution 8s infinite linear;
                text-align: center;
                font-size: 125px;
            }
            @keyframes changeSolution{
                0%   {transform: rotateX(0deg) rotateY(0deg);}
                25%  {transform: rotateX(90deg) rotateY(90deg);}
                50%  {transform: rotateX(180deg) rotateY(180deg);}
                75%  {transform: rotateX(270deg) rotateY(270deg);}
                100% {transform: rotateX(360deg) rotateY(360deg);}
            }
        </style>
        <script></script>
    </head>
    <body>
      <div class="rotateSquare">
              <div class="top"></div>
              <div class="bottom"></div>
              <div class="left"></div>
              <div class="right"></div>
              <div class="front"></div>
              <div class="back"></div>
      </div>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值