3D立体盒子练习

综合运用CSS转换知识,编写了一个简单的可旋转的立体盒子,可以结合学习笔记六来进行学习。

HTML关键代码:

复制代码
<body>
    <div class="box">
        <div class="top">1</div>
        <div class="bottom">2</div>
        <div class="left">3</div>
        <div class="right">4</div>
        <div class="before">5</div>
        <div class="back">6</div>
    </div>

</body>

CSS关键代码:

复制代码
<style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            box-sizing: border-box;
        }

        .box {
            margin: 20px auto;
            width: 100px;
            height: 100px;
            background-color: aqua;
            position: relative;
            transition: all 2s ease;
            transform-style: preserve-3d;
        }

        .box div {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 0px;
            top: 0px;
            text-align: center;
            line-height: 100px;
            font-size: 40px;

        }

        .box:hover{
            transform: rotateX(360deg) rotateY(360deg);
        }

        .top {
            transform: translatey(-100px) rotateX(90deg);
            transform-origin: center bottom;
            background-color: rgba(255, 0, 0, 0.8);
        }

        .bottom {
            background-color: rgba(0, 0, 0, 0.8);
            transform: translatey(100px) rotateX(-90deg);
            transform-origin: center top;
        }

        .left {
            background-color: rgba(0, 255, 0, 0.8);
            transform: translateX(-100px) rotateY(-90deg);
            transform-origin: right center;
        }

        .right {
            background-color: rgba(0, 0, 255, 0.8);
            transform: translateX(100px) rotateY(90deg);
            transform-origin: left center;
        }

        .before {
            background-color: rgba(255, 255, 0, 0.5);
            z-index: 10;
        }

        .back {
            background-color: rgba(255, 0, 255, 0.8);
            transform: translateZ(-100px);
        }
    </style>
相关推荐
ByNotD0g11 分钟前
Doris 学习笔记
android·笔记·学习
困死,根本不会19 分钟前
Qt Designer 基础操作学习笔记
开发语言·笔记·qt·学习·microsoft
new code Boy23 分钟前
NestJS、Nuxt.js 和 Next.js
前端·后端
WJSKad123525 分钟前
Focus瓶颈轻量化改进YOLOv26通道压缩与残差学习协同突破
学习·yolo
愚者游世35 分钟前
<algorithm> 中 remove、remove_if、remove_copy、remove_copy_if 详解
c++·学习·程序人生·职场和发展·visual studio
云边散步36 分钟前
godot2D游戏教程系列二(13)
笔记·学习·游戏·游戏开发
gameboy03137 分钟前
网络爬虫学习:应用selenium获取Edge浏览器版本号,自动下载对应版本msedgedriver,确保Edge浏览器顺利打开。
爬虫·学习·selenium
进击切图仔39 分钟前
执行 shell 脚本 5 种方式对比
前端·chrome
小蜗牛~向前冲39 分钟前
大模型学习系列-Embedding与向量数据库
人工智能·python·神经网络·学习·机器学习·embedding
局i40 分钟前
React 简单地图组件封装:基于高德地图 API 的实践(附源码)
前端·javascript·react.js