[CSS] Use CSS Transforms to Create Configurable 3D Cuboids
2023-09-14 08:59:13 时间
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; }
相关文章
- 前端的3D(css3版本)--淘宝造物节3D创景的制作
- CSS - 工具类 tool.css
- 为什么CSS这么难学?css核心知识点攻坚指南
- 日志服务接入方式之Unity 3D篇
- Unity 3D 2022.1 AND UnityHub 3.2 Patch
- 〖大前端 - 基础入门三大核心之CSS篇㉑〗- 3D变形 与空间移动
- 裸眼3D将是未来移动端的显示的主要技术
- echarts 3d饼图
- HTML5,不仅仅是看上去非常美(第二弹:打造最美3D机房)
- [Unity3D]Unity3D游戏开发3D选择场景中的对象,并显示轮廓效果强化版
- 【CSS】css转换、css过渡、css动画_09
- 【CSS】css概述、语法规范、基础选择器_01
- 【三】3D匹配Matching之外形匹配Shape—Based——get_shape_model_3d_contours()/get_shape_model_3d_params()算子
- 【三】3D匹配Matching之外形匹配Shape—Based——deserialize_shape_model_3d()算子
- PCL RANSAC拟合空间3D椭圆
- 在Windows10平台安装Blender 3D建模软件并调用Python API接口