HTML(29)——立体呈现

作用:设置元素的子元素是位于3D空间中还是平面中

属性名:transform-style

属性值:

  • flat:子级处于平面中
  • preserve-3d:子级处于3D空间

步骤:

  1. 父级元素添加 transform-style:preserve-3d
  2. 子级定位
  3. 调整子盒子的位置(位移或旋转)

演示:

复制代码
  <style>
    .cube {
      width: 200px;
      height: 200px;
      margin: 100px auto;
      background-color: rgb(106, 220, 116);
      transition: all 2s;
    }

    .cube div {
      width: 200px;
      height: 200px;
    }

    .front {
      background-color: #2180d4;
    }

    .back {
      background-color: #dd1e1e;
    }
  </style>
</head>

<body>
  <div class="cube">
    <div class="front"></div>
    <div class="back"></div>
  </div>
</body>

按照步骤父级添加transform-style: preserve-3d; 为了更好的视觉效果我又添加了视距transform-style: preserve-3d; 然后根据子绝父相 原则给它们定位,最后**transform: translateZ(80px)**将两个盒子分开,添加一个旋转的效果使其更明显。

复制代码
  <style>
    .cube {
      position: relative;
      width: 200px;
      height: 200px;
      margin: 100px auto;
      background-color: rgb(106, 220, 116);
      transition: all 2s;
      transform-style: preserve-3d;
      transform-style: preserve-3d;
    }

    .cube div {
      position: absolute;
      left: 0;
      top: 0;
      width: 200px;
      height: 200px;
    }

    .front {
      background-color: #2180d4;
      transform: translateZ(80px);
    }

    .back {
      background-color: #dd1e1e;
    }

    .cube:hover {
      transform: rotateY(180deg);
    }
  </style>
</head>

<body>
  <div class="cube">
    <div class="front">前面</div>
    <div class="back">后面</div>
  </div>
</body>
相关推荐
新手村领路人1 小时前
Firefox自定义备忘
前端·firefox
乖女子@@@1 小时前
css3新增-网格Grid布局
前端·css·css3
伐尘2 小时前
【CE】图形化CE游戏教程通关手册
前端·chrome·游戏·逆向
不想吃饭e2 小时前
在uniapp/vue项目中全局挂载component
前端·vue.js·uni-app
非凡ghost2 小时前
AOMEI Partition Assistant磁盘分区工具:磁盘管理的得力助手
linux·运维·前端·数据库·学习·生活·软件需求
UrbanJazzerati2 小时前
前端入门:margin居中、border、box-radius、transform、box-shadow、mouse事件、preventDefault()
前端·面试
蝎子莱莱爱打怪2 小时前
🚀🚀🚀嗨,一起来开发 开源IM系统呀!
前端·后端·github
Enddme2 小时前
《前端笔试必备:JavaScript ACM输入输出模板》
前端·javascript·面试
前端鱼2 小时前
前端面试中值得关注的js题
前端·面试
UnnamedOrange3 小时前
有来前后端部署
前端·后端