zoukankan      html  css  js  c++  java
  • [CSS] Use CSS Transforms to Create Configurable 3D Cuboids

    In this lesson, we use CSS transforms to create configurable 3D cuboids.

    Using CSS transforms in combination with scoped CSS variables, we are able to configure the height, width, and depth for cuboids without ever having to repeat those styles.

    *,
    *:before,
    *:after {
      box-sizing: border-box;
    }
    
    body {
      min-height: 100vh;
      background: hsl(210, 50%, 20%);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      perspective: 800px;
    }
    
    .cuboid {
      --width: 10vmin;
      --height: 20vmin;
      --depth: 30vmin;
      height: var(--height);
      width: var(--width);
      position: relative;
      transform: rotateX(24deg) rotateY(32deg);
      transform-style: preserve-3d;
    }
    
    .cuboid__side {
      background-color: hsla(0, 0%, 100%, 0.2);
      border: 1px solid hsl(0, 0%, 10%);
      position: absolute;
    }
    
    .cuboid__side:nth-of-type(1),
    .cuboid__side:nth-of-type(2) {
      --coefficient: -0.5;
      height: var(--height);
      width: var(--width);
      transform: translate3d(0, 0, calc(var(--depth) * var(--coefficient)));
    }
    
    .cuboid__side:nth-of-type(2) {
      --coefficient: 0.5;
    }
    
    .cuboid__side:nth-of-type(3),
    .cuboid__side:nth-of-type(4) {
      --rotation: 90deg;
      height: var(--height);
      width: var(--depth);
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%) rotateY(var(--rotation)) translate3d(0, 0, calc(var(--width) * -0.5));
    }
    
    .cuboid__side:nth-of-type(4) {
      --rotation: -90deg;
    }
    
    .cuboid__side:nth-of-type(5),
    .cuboid__side:nth-of-type(6) {
      --rotation: -90deg;
      height: var(--depth);
      width: var(--width);
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%) rotateX(var(--rotation)) translate3d(0, 0, calc(var(--height) * -0.5));
    }
    
    .cuboid__side:nth-of-type(6) {
      --rotation: 90deg;
    }
    
    .cuboid:nth-of-type(2) {
      --width: 5vmin;
      --height: 15vmin;
      --depth: 10vmin;
    }

  • 相关阅读:
    java集合归纳
    判断回文数
    29:四则运算计算表达式的值
    getOutString 输出弹出字符串
    两个字符串中不同元素的个数
    字符串各个字符ASCII值加5
    23:一个整数的二进制表示中有多少个1
    Java进程间通信
    转 双重检查锁定与延迟初始化
    Key-Value键值存储原理初识(NOSQL)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13881508.html
Copyright © 2011-2022 走看看