魔方

 <style>

        * {
            box-sizing: border-box;
        }

        html {
            height: 100%;
        }

        body {
            margin: 0;
            height: 100%;
            background: radial-gradient(circle, #333, #000 50%);
            position: relative;
            /* 控制自己内部标签的转化样式 */
            /* transform-style: preserve-3d; */
            perspective: 1000px;

        }

        main {
            width: 300px;
            height: 300px;
            /* outline 轮廓线 dashed 虚线 */
            outline: 2px dashed red;
            /* 使用绝对定位进行元素居中 */
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            transform-style: preserve-3d;
            animation-name: rotate;
            animation-duration: 4s;
            animation-timing-function: linear;
            animation-iteration-count: infinite;
        }

        @keyframes rotate {
            0% {
                transform: rotateX(0) rotateZ(0);
            }

            100% {
                transform: rotateX(360deg) rotateZ(360deg);
            }
        }

        .surface {
            width: 300px;
            height: 300px;
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0.5;
            box-shadow: 0 0 10px #fff;
            font-size: 40PX;
            color: white;
            /* text-align: center; */
            
        }

        /* 在浏览器环境中,每一个元素都有自己的坐标系
            元素的任何的变形,都是所在坐标系的变形,而不是元素本身 */
        .top {
            background-color: red;
            /* 想象旋转轴指向自己,正方向为正值 */
            transform: rotateX(90deg) translateZ(150px);
        }

        .bottom {
            background: orange;
            transform: rotateX(-90deg) translateZ(150px);
        }

        .left {
            background-color: yellow;
            transform: rotatey(90deg) translateZ(-150px);
        }

        .right {
            background-color: green;
            transform: rotatey(-90deg) translateZ(-150px);
        }

        .front {
            background-color: blue;
            /* 平移 */
            transform: translateZ(150px);
        }

        .back {
            background-color: purple;
            transform: translateZ(-150px) rotateX(180deg);
        }
    </style>
</head>

<body>
    <main>
        <div class="surface top">1</div>
        <div class="surface bottom">2</div>
        <div class="surface left">3</div>
        <div class="surface right">4</div>
        <div class="surface front">5</div>
        <div class="surface back">6</div>
    </main>
</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值