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. (C++20) consteval立即函数

    2024-07-10 14:16:01       68 阅读
  2. Linux呈现数据

    2024-07-10 14:16:01       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 14:16:01       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 14:16:01       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 14:16:01       90 阅读
  4. Python语言-面向对象

    2024-07-10 14:16:01       98 阅读

热门阅读

  1. Prompt Engineering 探险

    2024-07-10 14:16:01       26 阅读
  2. 机器学习之神经网络

    2024-07-10 14:16:01       33 阅读
  3. Lianwei 安全周报|2024.07.09

    2024-07-10 14:16:01       22 阅读
  4. 每天一个数据分析题(四百一十八)- 相关分析

    2024-07-10 14:16:01       24 阅读
  5. 计算机网络面试常见题目(一)

    2024-07-10 14:16:01       29 阅读
  6. vue配置sql规则

    2024-07-10 14:16:01       21 阅读
  7. ios 企业签名证书购买_iOS苹果企业签名须知

    2024-07-10 14:16:01       27 阅读
  8. android 使用系统工具bootchart统计开机时长

    2024-07-10 14:16:01       29 阅读
  9. 【工具分享】FOFA——网络空间测绘搜索引擎

    2024-07-10 14:16:01       26 阅读
  10. 物联网应用,了解一点 WWAN全球网络标准

    2024-07-10 14:16:01       27 阅读
  11. Jupyter Notebook详尽安装教程

    2024-07-10 14:16:01       23 阅读
  12. 实现淘客返利系统中的用户登录与权限管理

    2024-07-10 14:16:01       22 阅读