动态网格渐变
这是因为背景结构是动态的,颜色是平滑混合的,而且实际上使用了CSS。
网格渐变背景,结合了 CSS 的“radial-gradient”和“filter:blur()”,可对多个渐变进行分层并平滑地为其设置动画。
预览
Mesh Gradient
Smooth flowing colors
用例和功能
这种动画网格渐变非常适合看起来现代和动态的网站背景。
-
英雄部分: 可用作着陆页的第一个视图,以吸引访问者的注意力。
-
身份验证屏幕: 使登录和注册屏幕变得简单、更具吸引力。
-
卡片背景: 适合信用卡 UI 的背景和想要强调高级感的元素。
-
主要特点:
-
它是轻量级的,因为它仅使用 CSS 实现,不依赖于 Canvas 或 WebGL。
-
mix-blend-mode: screen和filter: Blur()的组合可以让颜色完美自然地混合。 -
指定“will-change:transform”以考虑渲染性能。
-
设计和用户体验要点
-
有机动画: 每个圆形元素的动画周期(持续时间)会发生变化,以创建不规则且自然的运动。
-
色彩和谐: 强烈对比的颜色,如霓虹粉色、鲜艳的蓝色、青色和黄色,混合在一起时会产生深度。
-
与玻璃形态的兼容性: 通过将“backdrop-filter”(背景模糊)应用于前景内容,您可以创建一个背景渐变精美透明的现代 UI。
如何定制
-
颜色更改: 您只需更改“.mesh-blob-*”类中“radial-gradient”的颜色即可创建与您的品牌颜色相匹配的原始渐变。
-
动画调整: 减少“@keyframes float*”中“translate”的移动量会产生更加适度和温和的移动。
-
模糊强度: 通过调整
.mesh-bg中filter:blur(60px)的值,可以使颜色边界更清晰或更平滑地混合。
实现代码
<div class="mesh-container">
<div class="mesh-bg">
<div class="mesh-blob mesh-blob-1"></div>
<div class="mesh-blob mesh-blob-2"></div>
<div class="mesh-blob mesh-blob-3"></div>
<div class="mesh-blob mesh-blob-4"></div>
</div>
<div class="mesh-content">
<h3 class="mesh-title">Mesh Gradient</h3>
<p class="mesh-subtitle">Smooth flowing colors</p>
</div>
</div>
<style>
.mesh-container {
position: relative;
width: 100%;
height: 400px;
overflow: hidden;
border-radius: 16px;
background-color: #030014;
display: flex;
align-items: center;
justify-content: center;
font-family: 'Inter', system-ui, sans-serif;
}
.mesh-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
filter: blur(60px);
z-index: 0;
opacity: 0.9;
}
.mesh-blob {
position: absolute;
border-radius: 50%;
mix-blend-mode: screen;
will-change: transform;
}
.mesh-blob-1 {
width: 400px;
height: 400px;
background: radial-gradient(circle, rgba(255, 0, 204, 0.8) 0%, rgba(255, 0, 204, 0) 70%);
top: -100px;
left: -100px;
animation: float1 15s infinite ease-in-out;
}
.mesh-blob-2 {
width: 500px;
height: 500px;
background: radial-gradient(circle, rgba(51, 51, 255, 0.8) 0%, rgba(51, 51, 255, 0) 70%);
bottom: -150px;
right: -100px;
animation: float2 18s infinite ease-in-out;
}
.mesh-blob-3 {
width: 450px;
height: 450px;
background: radial-gradient(circle, rgba(0, 255, 255, 0.6) 0%, rgba(0, 255, 255, 0) 70%);
top: 50px;
right: -50px;
animation: float3 20s infinite ease-in-out;
}
.mesh-blob-4 {
width: 350px;
height: 350px;
background: radial-gradient(circle, rgba(255, 204, 0, 0.6) 0%, rgba(255, 204, 0, 0) 70%);
bottom: 0px;
left: 50px;
animation: float4 22s infinite ease-in-out;
}
@keyframes float1 {
0% { transform: translate(0px, 0px) scale(1); }
33% { transform: translate(100px, 150px) scale(1.2); }
66% { transform: translate(-50px, 50px) scale(0.9); }
100% { transform: translate(0px, 0px) scale(1); }
}
@keyframes float2 {
0% { transform: translate(0px, 0px) scale(1); }
33% { transform: translate(-150px, -100px) scale(1.3); }
66% { transform: translate(100px, -50px) scale(0.8); }
100% { transform: translate(0px, 0px) scale(1); }
}
@keyframes float3 {
0% { transform: translate(0px, 0px) scale(1); }
33% { transform: translate(-100px, 100px) scale(1.1); }
66% { transform: translate(150px, -150px) scale(1.2); }
100% { transform: translate(0px, 0px) scale(1); }
}
@keyframes float4 {
0% { transform: translate(0px, 0px) scale(1); }
33% { transform: translate(150px, -150px) scale(0.9); }
66% { transform: translate(-150px, 150px) scale(1.3); }
100% { transform: translate(0px, 0px) scale(1); }
}
.mesh-content {
position: relative;
z-index: 1;
text-align: center;
color: white;
background: rgba(255, 255, 255, 0.05);
padding: 40px 60px;
border-radius: 24px;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.mesh-title {
margin: 0;
font-size: 2.5rem;
font-weight: 700;
letter-spacing: -1px;
background: linear-gradient(135deg, #fff, #e0e0e0);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.mesh-subtitle {
margin: 10px 0 0;
font-size: 1.1rem;
font-weight: 400;
color: rgba(255, 255, 255, 0.7);
}
</style> 浏览器兼容性状态
-
铬:支持
-
火狐浏览器:支持
-
Safari:支持(需要
-webkit-backdrop-filter前缀来模糊前景内容) -
边缘:支持