css实现元素由远及近的效果

【需求描述】transform实现元素由远及近的效果。
在这里插入图片描述

<!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>
        body,
        html {
      
      
            height: 100%;
        }

        body {
      
      
            display: flex;
            justify-content: center;
            align-items: center;
            perspective: 200px;
        }

        .square {
      
      
            background: skyblue;
            width: 200px;
            height: 200px;
            transform-style: preserve-3d;
            animation: move 5s linear;
            transform: translateZ(-100px);
        }

        @keyframes move {
      
      
            100% {
      
      
                transform: translateZ(100px);
            }
        }
    </style>
</head>

<body>
    <div class="square"></div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qzw752890913/article/details/126226497