栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

css毛玻璃效果(外加background属性)

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

css毛玻璃效果(外加background属性)

前因:

后果,二话不说,上效果:

注意:此方法只适合body设置背景图时的模糊。

页面布局方面,主要父元素为body,子元素为想要的效果,涉及到的知识点:background、filter、定位、伪元素、flex布局(主要为子元素水平居中使用)、z-index=-1也是很重要的一个点。

  1. background

    简单粗暴(https://www.w3school.com.cn/cssref/pr_background.asp)

    background: url('./timg1.jpg') no-repeat center fixed;

    分别对应:背景图片地址、平铺效果、滚动、位置

    同时也要标注背景图片尺寸background-size

    background-size: cover;

    上图:

  2. filter

    blur(px) 给图像设置高斯模糊。

    附上Filter函数的地址https://www.runoob.com/cssref/css3-pr-filter.html

  3. 定位

    常说的一句话“子绝父相”

  4. 伪元素

    布局中用了很多伪元素

  5. z-index=-1,通过设置使父元素内容在内容下面

代码:




    
    
    
    毛玻璃效果
    
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body,
        .item::before {
            background: url('./timg1.jpg') no-repeat center fixed;
            background-size: cover;
        }
        body {
            height: 100vh;
            width: 100vw;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .item {
            position: relative;
            width: auto;
            height: auto;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 5px 1px #fff;
            color: #fff;
            font-size: 15px;
            font-weight: lighter;
            line-height: 35px;
            overflow: hidden;
        }
        .item::before {
            content: '';
            display: block;
            position: absolute;
            z-index: -1;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: -20px;
            filter: blur(10px);
            
        }
    


    
        

            没有什么比时间更具有说服力了,
            因为时间无需通知我们就可以改变一切。
                                                                                                                              ——《活着》
        

    

若有不正确的地方请各位大佬指出,更多内容请参考:

https://www.jianshu.com/p/638e0007dc27



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/241888.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号