颗粒化的毛玻璃效果

前言

最近又看了一下css大佬 chokcoco 的文章发现这一篇 妙用 CSS 构建花式透视背景效果 文章,发现真的很有意思。每次看大佬的文章都能学到不少东西,因此根据大佬的教程自己也尝试一下。

饿了么具体效果可以查看饿了么官网,Element UI

在这里插入图片描述

不知道怎么说,大佬的css水平是真牛逼。

在这里插入图片描述

实现

看了一下大佬的介绍,原理就是渐变背景加上滤镜

颗粒背景

透明到黑色的径向渐变

<div></div>

div {
    width: 300px;
    height: 100px;

    // 设置径向渐变
    background: radial-gradient(transparent, #000 20px);
    background-size: 40px 40px;
}

在这里插入图片描述
需要注意的是,图里的白色部分应该是透明的,这样就可以透出背后的背景。

div {
    background: radial-gradient(transparent, rgba(255, 255, 255, 1) 2px);
    background-size: 4px 4px;
}

demo

<template>
    <div class="container">
        <div class="aa"></div>
        <p class="p1">111</p>
        <p class="p2">111</p>
        <p class="p3">111</p>
    </div>
</template>

<script setup lang="ts">

</script>
<style scoped lang="scss">
.container {
    width: 400px;
    height: 200px;
    overflow-y: auto;
}

.aa {
    position: fixed;
    width: 300px;
    height: 100px;

    // 设置径向渐变
    background: radial-gradient(transparent, rgba(255, 255, 255, 1) 2px);
    background-size: 4px 4px;
}

.p1 {
    width: 300px;
    height: 100px;
    background-color: red;
}

.p2 {
    width: 300px;
    height: 100px;
    background-color: blue;
}

.p3 {
    width: 300px;
    height: 200px;
    background-color: pink;
}
</style>

在这里插入图片描述

加上滤镜
此时透出的背景看上去非常生硬,也不美观,所以,我们还需要 backdrop-filter: blur()

div {
    background: radial-gradient(transparent, rgba(255, 255, 255, 1) 2px);
    background-size: 4px 4px;
    backdrop-filter: blur(10px);
}

在这里插入图片描述
这里需要注意的是,background-size 的大小控制,和不同的 backdrop-filter: blur(10px) 值,都会影响效果。

扩展

我们可以尝试替换掉 background: radial-gradient() 图形,及改变 background-size,尝试各种不同形状的透视背景。

<template>
    <div class="container">
        <div class="aa"></div>
        <p class="p1">111</p>
        <p class="p2">111</p>
        <p class="p3">111</p>
    </div>
</template>

<script setup lang="ts">

</script>
<style scoped lang="scss">
.container {
    width: 400px;
    height: 200px;
    overflow-y: auto;
}

.aa {
    position: fixed;
    width: 300px;
    height: 100px;

    background: linear-gradient(45deg, transparent, #fff 4px);
    background-size: 6px 6px;
    backdrop-filter: saturate(50%) blur(4px);
}

.p1 {
    width: 300px;
    height: 100px;
    background-color: red;
}

.p2 {
    width: 300px;
    height: 100px;
    background-color: blue;
}

.p3 {
    width: 300px;
    height: 200px;
    background-color: pink;
}
</style>

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无知的小菜鸡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值