CSS3_3D变换(七)

1、CSS3_3D变换

1.1 3D空间与景深

3D空间:在父元素中将属性transform-style设置为preserve-3d开启3D空间,默认值为flat(开启2D空间);

景深:人眼与平面的距离,产生透视效果,使得效果更加立体。

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>3D变换与景深</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;

            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;

            transform: rotateX(30deg);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.2 透视点的位置

透视点:人眼观察的位置,在父元素中设置。

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>透视点的位置</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;

            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
            /* 设置观察点的位置(在右下角观察) */
            perspective-origin: 500px 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;

            transform: rotateX(30deg);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.3 3D位移
html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>位移</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;

            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
            /* 设置观察点的位置(在右下角观察) */
            /* perspective-origin: 500px 200px; */
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;

            /* 设置Z轴距离,不能写百分比 */
            /* transform: translateZ(150px); */
            /* 设置在X、Y、Z轴的位移距离,可以写百分比 */
            transform: translate3d(12px, 50%, 3px);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.4 3D旋转
html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>旋转</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;

            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;
            /* 设置X轴旋转角度 */
            /* transform: rotateX(100deg); */
            /* 设置Y轴旋转角度 */
            /* transform: rotateY(100deg); */
            /* 设置X、Y、Z轴旋转角度倍数 */
            transform: rotate3d(1, 1, 1, 30deg);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.5 3D缩放
html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>缩放</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;
            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;


            /* 设置Z轴缩放比例,由于html元素没有厚度,则该属性调整景深,景深除以缩放的比例 */
            transform: scaleZ(4) rotateY(30deg);
            /* 设置3D缩放比例,X、Y、Z轴的缩放比例 */
            /* transform: scale3d(2,1,1) rotateY(30deg); */
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.6 3D多重变换
html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>多重变换</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;
            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;
            line-height: 200px;

            transform-origin: top 20px;
            transform: rotateX(60deg);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
1.7 3D背部
html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>背部</title>
    <style>
        .outer {
            height: 200px;
            width: 200px;
            border: 1px solid black;
            margin: 0 auto;
            margin-top: 100px;
            /* 开启3D空间 */
            transform-style: preserve-3d;
            /* 设置景深 */
            perspective: 500px;
        }

        .inner {
            height: 200px;
            width: 200px;
            background-color: aquamarine;
            text-align: center;
            line-height: 200px;

            transform: rotateY(180deg);
            /* 设置背部不可见 */
            backface-visibility: hidden;
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="inner">
            示例文字
        </div>
    </div>
</body>

</html>
相关推荐
weixin_4896900231 分钟前
MicroSIP自定义web拨打协议
服务器·前端·windows
幻云201044 分钟前
Python机器学习:筑基与实践
前端·人工智能·python
web小白成长日记1 小时前
Vue3中如何优雅实现支持多绑定变量和修饰符的双向绑定组件?姜姜好
前端·javascript·vue.js
晴天飛 雪1 小时前
Spring Boot 接口耗时统计
前端·windows·spring boot
0思必得01 小时前
[Web自动化] Selenium模拟用户的常见操作
前端·python·selenium·自动化
Apifox.1 小时前
测试用例越堆越多?用 Apifox 测试套件让自动化回归更易维护
运维·前端·后端·测试工具·单元测试·自动化·测试用例
玉梅小洋1 小时前
Chrome设置链接自动跳转新标签页而不是覆盖
前端·chrome
EndingCoder2 小时前
反射和元数据:高级装饰器用法
linux·运维·前端·ubuntu·typescript
Marshmallowc2 小时前
React性能优化:useState初始值为什么要用箭头函数?深度解析Lazy Initialization与Fiber机制
前端·react.js·性能优化·前端框架·react hooks
Coder_Boy_2 小时前
基于SpringAI的在线考试系统-试卷管理模块完整优化方案
前端·人工智能·spring boot·架构·领域驱动