HTML/CSS实现毛玻璃特效的两种方法

我想要设置类似于苹果和windows10的毛玻璃效果,比如这样:

在这里插入图片描述
其实就是一圈高斯模糊,我认为底层可以实现的方式有两种:高斯模糊和领域池化。

以下实现视觉上的毛玻璃效果有两种,后者为伪毛玻璃,而且在视觉效果上比较适合用在纯色或者渐变纯色的背景上。

方法一:使用blur

在网页设计中将对应的组件的backdrop-filter属性设置为blur即可,blur的参数为高斯模糊的半径,一般设置为50px即可。给个小demo:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tranplate1</title>
    <style>
        body{
      
      
            background-image: linear-gradient(to right top, #65dfc9, #6cdbeb);
            align-items: center;
            justify-content: center;
            display: flex;
        }
        .main{
      
      
            background-color: rgba(255, 255, 255, 0.4);
            position: relative;
            width: 60%;
            height: 600px;
            box-shadow: 0 5px 15px rgba(20, 20, 20, 0.8);
            display: flex;
            border-radius: 50px;
            align-items: center;
            top: 100px;
            backdrop-filter: blur(50px);
        }
    </style>
</head>
<body>
    <div class="main"></div>
</body>
</html>

效果如下图的右侧
在这里插入图片描述

方法二:透明通道的线性差值

之前在逛油管时逛到的方法,对于你的渐变色背景可以做出伪毛玻璃特效,简单说就是使用linear-gradient对你的背景做线性差值就行,其中的始末状态为rgba(255,255,255,0.3)rgba(255,255,255,0.7),例子如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Transplate2</title>
    <style>
        body{
      
      
            background-image: linear-gradient(to right top, #65dfc9, #6cdbeb);
            align-items: center;
            justify-content: center;
            display: flex;
        }
        .main{
      
      
            background-image: linear-gradient(to right top, rgba(255,255,255,0.3), rgba(255,255,255,0.7));
            position: relative;
            width: 60%;
            height: 600px;
            box-shadow: 0 5px 15px rgba(20, 20, 20, 0.8);
            display: flex;
            border-radius: 50px;
            align-items: center;
            top: 100px;
        }
    </style>
</head>
<body>
    <div class="main"></div>
</body>
</html>

效果如下:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45576923/article/details/117756508