css3之3D转换transform

css3之3D转换

  • 一.特点
  • 二.坐标系
  • 三.3D移动(translate3d)
    • 1.概念
    • 2.透视(perpective)(近大远小)(写在父盒子上)
  • 四.3D旋转(rotate3d)
    • 1.概念
    • 2.左手准则
    • 3.呈现(transfrom-style)(写父级盒子上)
    • 4.总结
  • 五.案例
    • 1.两面旋转
    • 2.导航栏
    • 3.旋转木马

一.特点

近大远小,后面看不见

二.坐标系

三.3D移动(translate3d)

1.概念

2.透视(perpective)(近大远小)(写在父盒子上)

四.3D旋转(rotate3d)

1.概念

2.左手准则

(1)沿着x轴旋转

(2)沿着y轴旋转

3.呈现(transfrom-style)(写父级盒子上)

4.总结

五.案例

1.两面旋转


css 复制代码
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            perspective: 350px;

        }

        .box {
            position: relative;
            width: 300px;
            height: 300px;
            margin: 100px auto;
            transition: all .4s;
            transform-style: preserve-3d;
        }

        .box:hover {
            transform: rotateY(180deg);
        }

        .front,
        .back {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            font-size: 30px;
            color: #fff;
            text-align: center;
            line-height: 300px;

        }

        .front {
            background-color: pink;
            z-index: 1;
        }

        .back {
            background-color: purple;
            /*背对背旋转180deg,字不会镜像*/
            transform: rotateY(180deg);


        }
    </style>
</head>

<body>
    <div class="box">
        <div class="front">黑马程序员</div>
        <div class="back">pink老师等你</div>
    </div>
</body>

</html>

2.导航栏

css 复制代码
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    ul {
        margin: 100px;
    }

    ul li {
        float: left;
        margin: 0 5px;
        width: 120px;
        height: 35px;
        list-style: none;
        perspective: 500px;
    }

    .box {
        position: relative;
        width: 100%;
        height: 100%;
        transform-style: preserve-3d;
        transition: all .4s;
        text-align: center;
        font-size: 16px;
        line-height: 35px;
    }

    .box:hover {
        transform: rotateX(90deg);
    }

    .front,
    .bottom {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;

    }

    .front {
        background-color: pink;
        z-index: 1;
        transform: translateZ(17.5px);
    }

    .bottom {
        background-color: purple;
        transform: translateY(17.5px) rotateX(-90deg);
    }
</style>

<body>
    <ul>
        <li>
            <div class="box">
                <div class="front">黑马程序员</div>
                <div class="bottom">pink老师等你</div>
            </div>
        </li>
    </ul>
</body>

</html>

3.旋转木马

css 复制代码
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            perspective: 600px;
        }

        section {
            position: relative;
            width: 300px;
            height: 200px;
            margin: 250px auto;
            transform-style: preserve-3d;
            animation: rotate 10s linear infinite;

        }

        section div {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: url(001a3fe237b2c5e71eeca0a5ca44c68c.png) no-repeat;
            background-size: 300px 200px;

        }

        section:hover {
            animation-play-state: paused;
        }

        section div:nth-child(1) {

            transform: rotateY(60deg) translateZ(300px);
        }

        section div:nth-child(2) {

            transform: rotateY(120deg) translateZ(300px);
        }

        section div:nth-child(3) {

            transform: rotateY(180deg) translateZ(300px);
        }

        section div:nth-child(4) {

            transform: rotateY(240deg)translateZ(300px);
        }

        section div:nth-child(5) {

            transform: rotateY(300deg)translateZ(300px);
        }

        section div:nth-child(6) {

            transform: rotateY(360deg)translateZ(300px);
        }

        @keyframes rotate {
            0% {
                transform: rotateY(0);
            }

            100% {
                transform: rotateY(360deg);
            }
        }
    </style>
</head>

<body>
    <section>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </section </body>

</html>
相关推荐
先生沉默先1 分钟前
3dsMax合并FBX的时候相同的节点会被合并(重命名解决),3Ds MAX创建空物体(虚拟对象或者点)
3d·3dsmax
煸橙干儿~~1 分钟前
分析JS Crash(进程崩溃)
java·前端·javascript
安冬的码畜日常11 分钟前
【D3.js in Action 3 精译_027】3.4 让 D3 数据适应屏幕(下)—— D3 分段比例尺的用法
前端·javascript·信息可视化·数据可视化·d3.js·d3比例尺·分段比例尺
l1x1n038 分钟前
No.3 笔记 | Web安全基础:Web1.0 - 3.0 发展史
前端·http·html
昨天;明天。今天。1 小时前
案例-任务清单
前端·javascript·css
zqx_72 小时前
随记 前端框架React的初步认识
前端·react.js·前端框架
惜.己2 小时前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
什么鬼昵称3 小时前
Pikachu-csrf-CSRF(get)
前端·csrf
Death2003 小时前
Qt 3D、QtQuick、QtQuick 3D 和 QML 的关系
c语言·c++·qt·3d·c#
长天一色3 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript