其他分享
首页 > 其他分享> > CSS背景图模糊,内容保持清晰

CSS背景图模糊,内容保持清晰

作者:互联网

效果:
在这里插入图片描述

代码:

<!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>背景毛玻璃效果</title>

    <style>
        .container {

            width: 100%;

            height: 100vh;

            background-image: url("../static/yyqx.jpg");

            background-repeat: no-repeat;

            background-attachment: fixed;

            background-size: cover;

            overflow: hidden;

        }



        .frosted-glass {

            width: 100%;

            height: 100vh;

            background: inherit;

            -webkit-filter: blur(5px);

            -moz-filter: blur(5px);

            -ms-filter: blur(5px);

            -o-filter: blur(5px);

            filter: blur(5px);

            filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=4, MakeShadow=false);

        }


        .content{

            position: absolute;

            top: 50%;

            left: 50%;

            transform: translate(-50%, -50%);

            color: #fff;

        }

    </style>

</head>


<body>

    <div class="container">

        <div class="frosted-glass"></div>

        <div class="content">
            <p>如果blur直接加在.container上,.container内的内容也会模糊</p>
            <p>所以要加一个遮罩层 .frosted-glass</p>
            <p>但加了.frosted-glass以后,会占据标准文档流,所以其他内容要脱离标准文档流才能显示在毛玻璃上方</p>
        </div>

    </div>

</body>

</html>

标签:vw,5px,vh,模糊,filter,background,blur,背景图,CSS
来源: https://blog.csdn.net/http____/article/details/122018318