首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >css 背景图片虚化效果

css 背景图片虚化效果

作者头像
lin_zone
发布2018-08-20 15:47:10
3.8K0
发布2018-08-20 15:47:10
举报
文章被收录于专栏:LIN_ZONELIN_ZONE

转载地址:http://blog.csdn.net/ohehehou/article/details/51975539

需求:一个div设置了background: url,现在需要使图片背景模糊,div内的文字清晰显示。

原始代码:

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <style type="text/css">
        .content {
            color: #ffffff;
            font-size: 40px;
        }
        .bg {
            background: url('1.jpg');
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            height:600px;
            text-align: center;
            line-height: 600px;
        }
    </style>
</head>
<body>
<div class="bg">
    <div class="content">我是内容</div>
</div>
</body>
</html>

原始效果: 

解决方法:内容和图片分别置于一个div,通过css设置背景div模糊度,设置内容div绝对位置。

html代码:

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <style type="text/css">
        .content {
            color: #ffffff;
            font-size: 40px;
        }
        .bg {
            background: url('1.jpg');
            height:600px;
            text-align: center;
            line-height: 600px;
        }
        .bg-blur {
            float: left;
            width: 100%;
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            -webkit-filter: blur(15px);
            -moz-filter: blur(15px);
            -o-filter: blur(15px);
            -ms-filter: blur(15px);
            filter: blur(15px);
        }
        .content-front {
          position:absolute;
          left: 10px;
          right: 10px;
          height:600px;
          line-height: 600px;
          text-align: center;
        }

    </style>
</head>
<body>
    <div>
        <div class="bg bg-blur"></div>
        <div class="content content-front">我是内容</div>
    </div>
</div>
</body>
</html>

效果: 

 注:相似的效果可以通过以上的代码改进而来

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-05-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档