动画·
CSS属性
backdrop-filter
: 这个属性可以对元素背后的区域应用图形效果(如模糊、对比度调整等)。我们通常使用blur()函数来实现模糊效果。
background-color
: 通过设置半透明的背景颜色,可以增强磨砂玻璃的效果。通常使用rgba()来定义颜色和透明度。
案例
<!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 {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
/* .wrap 渐变背景 */
.wrap {
width: 100%;
height: 100vh;
background: linear-gradient(135deg, #6a11cb, #2575fc);
display: flex;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
}
/* h2 白色字体居中 */
.wrap h2 {
color: white;
font-size: 2.5rem;
text-align: center;
}
/* .modal 磨砂玻璃效果 */
.modal {
width: 300px;
height: 200px;
/* 半透明背景 */
background-color: rgba(255, 255, 255, 0.1);
/* 磨砂玻璃模糊效果 */
backdrop-filter: blur(2px);
/* 圆角 */
border-radius: 15px;
/* 半透明边框 */
border: 1px solid rgba(255, 255, 255, 0.2);
/* 阴影 */
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="wrap">
<h2>磨砂玻璃效果</h2>
<div class="modal"></div>
</div>
</body>
</html>