< div>模糊的背景图像的一部分,用css [英] <div> blur of part of Background image with css

查看:153
本文介绍了< div>模糊的背景图像的一部分,用css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此可以使用-webkit-filter:blur();在背景图像上?解决方案以制作模糊的背景图像,效果很好!但是我想在背景上添加一些<div>并使其模糊.因此,背景应该仅在<div>下清晰且模糊.如果我在该div上移动模糊滤镜,它会变得模糊,但背景图像仍然清晰.

I use this Is it possible to use -webkit-filter: blur(); on background-image? solution to make blurry backgroung image and it works great! But I want to make some <div> over background and make it blurry. So background should be clear and blurry under <div> only. If I move blur filter on that div it became blur, but background image still clear.

HTML很简单:

<body>
   <div class = "background"></div>
   <div class = "content"></div>
</body>

CSS是:

.content{
    width: 70%;
    height: 70%;
    border:2px solid;
    border-radius:20px;
    position: fixed;
    top: 15%;
    left: 15%;
    z-index:10;
    background-color: rgba(168, 235, 255, 0.2);
    filter: blur(2px); 
    -webkit-filter: blur(2px);
    -moz-filter: blur(2px);
    -o-filter: blur(2px); 
    -ms-filter: blur(2px);
}
.background{
    width:100%;
    height:100%;
    background-image:url('http://www.travel.com.hk/region/time_95.jpg');
    z-index:0;
    position:absolute;
}

以下是示例 http://jsfiddle.net/photolan/8gVGR/

所以我只需要使用CSS模糊content div下的背景.

So I need to blur background under content div only with CSS.

推荐答案

如果它必须是动态的,您应该会遇到一些麻烦,但是您可以从这里开始:

If it has to be dynamic, you should have some trouble, but you can have somewhere to start with this :

HTML

<div class="background"></div>
<div class="mask">
    <div class="bluredBackground"></div>
</div>
<div class="content"></div>

CSS

.content {
    width: 70%;
    height: 70%;
    border:2px solid;
    border-radius:20px;
    position: fixed;
    top: 15%;
    left: 15%;
    z-index:10;
    background-color: rgba(168, 235, 255, 0.2);
}
.background {
    width:100%;
    height:100%;
    background-image:url('http://www.travel.com.hk/region/time_95.jpg');
    z-index:2;
    position:fixed;
}
.bluredBackground {
    width:100%;
    height:100%;
    display:block;
    background-image:url('http://www.travel.com.hk/region/time_95.jpg');
    z-index:1;
    position:absolute;
    top:-20%;
    left:-20%;
    padding-left:20%;
    padding-top:20%;
    -webkit-filter: blur(2px);
}
.mask {
    width: 70%;
    height: 70%;
    border:2px solid;
    border-radius:20px;
    position: fixed;
    top: 15%;
    left: 15%;
    z-index:10;
    overflow:hidden;
}

FIDDLE

FIDDLE

这篇关于&lt; div&gt;模糊的背景图像的一部分,用css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆