美文网首页
14.背景模糊filter

14.背景模糊filter

作者: 最爱喝龙井 | 来源:发表于2019-10-07 15:55 被阅读0次

    背景模糊

    filter: blur(9px)
    实现背景模糊的思路:通过给父元素的after伪元素设置模糊,来模拟父元素的背景模糊,然后我们通过定位元素层级来突出显示内容部分,这样就防止后代继承模糊了

    代码如下:

    <!DOCTYPE html>
    <html lang="zh-CN">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <link rel="stylesheet" href="">
        <style>
            * {
                margin: 0;
                padding: 0;
            }
            .bg {
                width: 100%;
                height: 100%;
                position: relative;
                background: url("images/bg.jpg") no-repeat fixed;
                padding: 1px;
                box-sizing: border-box;
                z-index: 1;
            }
    
            .bg:after {
                content: "";
                width: 100%;
                height: 700px;
                position: absolute;
                left: 0;
                top: 0;
                background: inherit;
                filter: blur(10px);
                z-index: 2;
            }
    
            .drag {
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                width: 200px;
                height: 200px;
                text-align: center;
                color: red;
                z-index: 11;
            }
        </style>
    </head>
    
    <body>
        <div class="bg">
            <div class="drag">hello world</div>
        </div>
    
    </body>
    
    </html>
    

    效果如下:

    image.png

    相关文章

      网友评论

          本文标题:14.背景模糊filter

          本文链接:https://www.haomeiwen.com/subject/orsmpctx.html