backdrop-filter(纯CSS实现丝滑边框线条动画)

即便绝对定位的子盒子视觉上覆盖在父盒子上,导致父盒子的内容或背景不可见,backdrop-filter 依然作用于父盒子自己的背景及背后的内容上。简而言之,backdrop-filter 是针对元素自身及其背后内容的一个效果,它不受该元素内子元素定位方式的影响。因此,即便子盒子“脱标”,父盒子的 backdrop-filter 依然可以对其背后的内容生效,只是可能由于子盒子的遮挡,视觉上不容易直接观察到这一效果。

点击查看代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>纯CSS实现丝滑边框线条动画</title>
</head>
<style>
    body {
        background-color: black;
    }

    .outer {
        position: relative;
        width: 400px;
        height: 200px;
        margin: 50px;
        /* 确保有足够空间显示动画 */
        border-radius: 30px;
        overflow: hidden;
        padding: 1px;
    }

    .inner {
        background: rgba(9, 9, 11, 0.38);
        border: 1px solid rgb(30, 41, 59);
        width: 100%;
        height: 100%;
        border-radius: 30px;
        -webkit-backdrop-filter: blur(24px);
        backdrop-filter: blur(24px);
        box-sizing: border-box;
    }

    .moving-element {
        position: absolute;
        top: 0;
        left: 40px;
        width: 80px;
        height: 80px;
        background-image: radial-gradient(#cbacf9 40%, transparent 80%);
        border-radius: 40px;
        animation: moveAround 8s linear infinite;
        transform: translate(-40px, -40px);
    }

    @keyframes moveAround {

        0% {
            left: 40px;
            top: 0px;
        }

        28.93% {
            left: 360px;
            top: 0px;
        }

        33.99% {
            left: 400px;
            top: 40px;
        }

        44.82% {
            left: 400px;
            top: 160px;
        }

        49.88% {
            left: 360px;
            top: 200px;
        }

        78.81% {
            left: 40px;
            top: 200px;
        }

        83.87% {
            left: 0px;
            top: 160px;
        }

        94.70% {
            left: 0px;
            top: 40px;
        }

        100% {
            left: 40px;
            top: 0px;
        }
    }
</style>

<body>
    <div class="outer">
        <div class="moving-element">

        </div>
        <div class="inner">

        </div>

    </div>
</body>

</html>
posted @   jialiangzai  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡

喜欢请打赏

扫描二维码打赏

微信打赏

点击右上角即可分享
微信分享提示