CSS变形与动画(二):perspctive透视效果 与 preserve-3d 3d效果(奥运五环例子)

文章目录

    • [perspective 3d透视效果](#perspective 3d透视效果)
    • [preserve-3d 3d嵌套效果](#preserve-3d 3d嵌套效果)
      • [例子 奥运五环](#例子 奥运五环)
    • [backface-visibility 背面效果](#backface-visibility 背面效果)

perspective 3d透视效果

perspective 指定了观察者与 z=0 平面的距离,使具有三维位置变换的元素产生透视效果。z>0 的三维元素比正常大,而 z<0 时则比正常小,大小程度由该属性的值决定。

作用于在父级上。

preserve-3d 3d嵌套效果

相互可以视觉上 插入 和 覆盖

transform-style: preserve-3d; 也是用在父级

例子 奥运五环

通过每个环细微的旋转角度实现。

主要看各环之间的覆盖关系,这就是3d嵌套的效果。

css 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .mb{
            background: pink;
            height:600px;
            display: flex;
            justify-content: center;
        }
        .m{
            padding-top: 200px;
            width:360px;
            height: 200px;
            display: flex;
            flex-wrap: wrap;
            transform-style: preserve-3d;
        }
        .l{
            margin: 2px;
        }
        .l:nth-child(1){
            width:100px;
            height: 100px;
            border:7px solid blue;
            border-radius: 100%;
            transform: rotateX(-1deg) rotateY(-2deg);

        }
        .l:nth-child(2){
            width:100px;
            height: 100px;
            border:7px solid black;
            border-radius: 100%;
            transform: rotateX(-1deg) rotateY(-2deg);
        }
        .l:nth-child(3){
            width:100px;
            height: 100px;
            border:7px solid red;
            border-radius: 100%;
            transform: rotateX(-3deg) rotateY(-3deg);
        }
        .l:nth-child(4){
            width:100px;
            height: 100px;
            border:7px solid yellow;
            border-radius: 100%;
            position: relative;
            left:56px;
            bottom: 60px;
            transform: rotateX(0deg) rotateY(2deg);
        }
        .l:nth-child(5){
            width:100px;
            height: 100px;
            border:7px solid green;
            border-radius: 100%;
             position: relative;
            left:56px;
            bottom: 60px;
            transform: rotateX(2deg) rotateY(4deg);
        }
    </style>
</head>
<body>
    <div class="mb">
        <div class="m">
            <div class="l"></div>
            <div class="l"></div>
            <div class="l"></div>
            <div class="l"></div>
            <div class="l"></div>
        </div>
    </div>
</body>
</html>

backface-visibility 背面效果

backface-visibility: hidden; 背面不可见

相关推荐
座山雕~28 分钟前
html 和css基础常用的标签和样式(2)-css
前端·css·html
叉歪1 小时前
实现在 UnoCSS 中使用任意深度颜色的预设
前端·css
charlie1145141911 小时前
CSS学习笔记3:颜色、字体与文本属性基础
css·笔记·学习·教程·基础
Sherry0072 小时前
【译】🔥如何居中一个 Div?看这篇就够了
前端·css·面试
Qinana3 小时前
🚙微信小程序实战解析:打造高质感汽车展示页
前端·css·程序员
有点笨的蛋3 小时前
深入前端工程的细枝末节:那些被忽略却决定页面体验的 CSS 关键细节
前端·css
Revol_C3 小时前
【Element Plus】升级版本后,el-drawer自定义的关闭按钮离奇消失之谜
前端·css·vue.js
Watermelo6174 小时前
从vw/h到clamp(),前端响应式设计的痛点与进化
前端·javascript·css·算法·css3·用户界面·用户体验
Moment4 小时前
快到  2026  年了:为什么我们还在争论  CSS 和 Tailwind?
前端·javascript·css
dllxhcjla4 小时前
css第一天
java·前端·css