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>
本文来自博客园,作者:jialiangzai,转载请注明原文链接:https://www.cnblogs.com/zsnhweb/p/18221991
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡