当前位置: 首页 > news >正文

CSS3 3D转换模块-正方体,长方体

正方体1— 这个实现过程中,先平移后旋转,坐标轴不变

<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> <style> *{ margin: 0; padding: 0; } ul{ width: 200px; height: 200px; border: 1px solid #000; box-sizing: border-box; margin: 100px auto; position: relative; transform: rotateY(0deg) rotateX(0deg);//给ul增加一个3d效果,下面的效果图都是改变这两个参数值手动f12旋转得到 transform-style: preserve-3d; } ul li{ list-style: none; width: 200px; height: 200px; font-size: 60px; text-align: center; line-height: 200px; position: absolute;//所有的li重叠在ul中 left: 0; top: 0; } ul li:nth-child(1){ background-color: red; transform: translateX(-100px) rotateY(90deg);//因为要绕正方体中心轴旋转,所以先沿x轴向左移动边长的一半,之后绕y轴转90度,形成左面 } ul li:nth-child(2){ background-color: green; transform: translateX(100px) rotateY(90deg);//形成右面 } ul li:nth-child(3){ background-color: blue; transform: translateY(-100px) rotateX(90deg);//形成上面 } ul li:nth-child(4){ background-color: yellow; transform: translateY(100px) rotateX(90deg);//形成下面 } ul li:nth-child(5){ background-color: purple; transform: translateZ(-100px);//形成前面 } ul li:nth-child(6){ background-color: pink; transform: translateZ(100px);//形成后面 } </style>

如果注释掉li3-6,f12改动ul的rotateY(0deg)值,从0到180度,效果如下:

综合之后,六个面写全,则效果图如下:

正方体2— 下面这个实现过程中,先旋转后平移,坐标轴根据旋转改变方向

<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> <style> *{ margin: 0; padding: 0; } ul{ width: 200px; height: 200px; border: 1px solid #000; box-sizing: border-box; margin: 100px auto; position: relative; transform: rotateY(0deg) rotateX(0deg); transform-style: preserve-3d; } ul li{ list-style: none; width: 200px; height: 200px; font-size: 60px; text-align: center; line-height: 200px; position: absolute; left: 0; top: 0; } ul li:nth-child(1){ background-color: red; transform: rotateX(90deg) translateZ(100px);//先旋转后平移,坐标轴随之旋转 } ul li:nth-child(2){ background-color: green; transform: rotateX(180deg) translateZ(100px);//先旋转后平移,坐标轴随之旋 } ul li:nth-child(3){ background-color: blue; transform: rotateX(270deg) translateZ(100px);//先旋转后平移,坐标轴随之旋 } ul li:nth-child(4){ background-color: yellow; transform: rotateX(360deg) translateZ(100px);//先旋转后平移,坐标轴随之旋 } ul li:nth-child(5){//5和6是左右两个面 background-color: purple; transform: translateX(-100px) rotateY(90deg); } ul li:nth-child(6){ background-color: pink; transform: translateX(100px) rotateY(90deg); } </style>

解释说明:

坐标轴旋转

以1为例

效果图

长方体

正方体变长方体,只需要在1~4的ul li:nth-child(i)中的transform属性后面添加scale(2, 1)即可,这个属性意为拉伸。如下:

ul li:nth-child(1){ background-color: red; transform: rotateX(90deg) translateZ(100px) scale(2, 1); }

在5和6中设置如下:

ul li:nth-child(5){ background-color: purple; transform: translateX(-200px) rotateY(90deg); } ul li:nth-child(6){ background-color: pink; transform: translateX(200px) rotateY(90deg); }

手动f12改变ul中绕x轴旋转效果:

长方体无限自动循环

<body> <ul> <li><img src="images/banner1.png" alt=""></li> <li><img src="images/banner2.jpg" alt=""></li> <li><img src="images/banner3.jpg" alt=""></li> <li><img src="images/banner4.jpg" alt=""></li> <li></li> <li></li> </ul> </body> <style> *{ margin: 0; padding: 0; } body{ /*想看到整个立方的近大远小效果, 就给ul的父元素添加透视*/ perspective: 500px; } ul{ width: 200px; height: 200px; box-sizing: border-box; margin: 100px auto; position: relative; transform: rotateY(0deg) rotateX(0deg); transform-style: preserve-3d; animation: sport 5s linear 0s infinite normal; } ul li{ list-style: none; width: 200px; height: 200px; font-size: 60px; text-align: center; line-height: 200px; position: absolute; left: 0; top: 0; } ul li:nth-child(1){ background-color: red; transform: rotateX(90deg) translateZ(100px) scale(2, 1); } ul li:nth-child(2){ background-color: green; transform: rotateX(180deg) translateZ(100px) scale(2, 1); } ul li:nth-child(3){ background-color: blue; transform: rotateX(270deg) translateZ(100px) scale(2, 1); } ul li:nth-child(4){ background-color: yellow; transform: rotateX(360deg) translateZ(100px) scale(2, 1); } ul li:nth-child(5){ background-color: purple; transform: translateX(-200px) rotateY(90deg); } ul li:nth-child(6){ background-color: pink; transform: translateX(200px) rotateY(90deg); } ul li img{ /* 注意点: 只要父元素被拉伸了,子元素也会被拉伸 */ width: 200px; height: 200px; } @keyframes sport { from{ transform: rotateX(0deg); } to{ transform: rotateX(360deg); } } </style>

效果图:

http://www.jsqmd.com/news/1282015/

相关文章:

  • 绥宁县新房除甲醛公司测评对比,本地业主实测,选邵阳森呼吸更省心 - 专注室内空气检测治理
  • 2026新版汉中防水补漏服务商参考|阳台渗漏修缮方案指南 - 筑宅安
  • 花都招聘平台哪个好:【帅聘网】实力认证 - MXyuyu
  • 【Springboot毕设全套源码+文档】基于SpringBoot的艺术作品展示平台的设计与实现(丰富项目+远程调试+讲解+定制)
  • 基于行空板与ChatGPT API的智能硬件创客项目:乐观新闻播报器
  • 佛山夏令营:军博营地专业 - 17728098551
  • 2026 AI低代码破局:企业数字化落地的高效解法
  • 2026年句容黄金回收行情深度剖析:透视价格逻辑与避坑实录 - 微城市网络
  • 抖音下载器V2.0:从零开始掌握高效批量下载技巧
  • 终极OpenCore安装指南:从零开始构建稳定黑苹果系统
  • 2026深圳GEO知识库搭建能力榜:微盟星启智能优势显
  • 2026武汉家装公司推荐:靠谱家装机构深度解析与选型指南 - 极欧测评
  • GetQzonehistory:重新发现你的数字记忆时光机
  • 2026陕西沥青路面施工厂家哪家好?避开4大坑,选对沥青路面公司 - GEO99
  • 【2026本溪闲置大牌处理指南】平山到明山,本溪人的LV、古驰、宝格丽去哪变现更稳妥? - 你就像风一样
  • 物联网设备安全芯片SE050与STM32F031C6集成实战
  • AI 基础设施建设中的决策陷阱:技术选型、团队能力与时间约束的博弈分析
  • 三大论文数据库AIGC检测机制与降AI工具对比分析
  • 2026数字化破局:低代码,不止降本,更重落地
  • 如何快速配置游戏存档:面向玩家的完整解决方案
  • 上海翡翠回收:2026年高端翡翠价格逆势走高,涨跌分化格局清晰 - 全城热点
  • 利用PostExpKit插件实现Windows UAC绕过提权实战指南
  • 2026年7月GEO效果可追踪力对比:微盟星启数据透明
  • 开源一套.NET平台的Excel COM 组件二次封装库
  • 算法(11):Convex hull-5.6
  • Linux学习从零到实战:一周构建操作系统思维与核心技能
  • 如何快速解密QQ音乐加密文件:QMCDecode完整使用指南
  • 义乌黄金回收,五套路了,无折旧费 - 新芸鼎珠宝首饰
  • 树莓派config.txt配置全解析:从显示、超频到硬件接口
  • 基于Micro:bit与LD3320的语音控制贪吃蛇项目实战