是否可以使用-webkit-filter:blur(); 在背景图像?

Eli*_*ynn 31 css css3

是否可以-webkit-filter: blur();在背景图像上使用?

我尝试过这个代码,它只是模糊了背景图像以外的一切:

body {
  background-image: url('http://www.publicdomainpictures.net/pictures/10000/velka/pebbles-and-sea-11284647414Rbeh.jpg');
  background-attachment: fixed;
  -webkit-filter: blur(5px);
}
Run Code Online (Sandbox Code Playgroud)

我一直在搜索,但找不到任何描述如何执行此操作的资源.

Jua*_*eda 47

未来用户:IE7,IE8,IE9,IE10,IE11或当前版本的EDGE不支持此功能.

除非您有后备,否则请勿在真实网站上使用.

如果您正在寻找不依赖于额外标记的解决方案,您可以将背景图像和过滤器应用于主体上的伪元素.

body {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    height: 100%;
}
body:before {
    content: "";
    position: absolute;
    background: url(http://lorempixel.com/420/255);
    background-size: cover;
    z-index: -1; /* Keep the background behind the content */
    height: 20%; width: 20%; /* Using Glen Maddern's trick /via @mente */

    /* don't forget to use the prefixes you need */
    transform: scale(5);
    transform-origin: top left;
    filter: blur(2px);
}
Run Code Online (Sandbox Code Playgroud)

看看这个JsFiddle.

  • @RickCalder真的吗?这是关于Webkit过滤器,即使IE11也不支持它. (11认同)

Ric*_*der 21

不要将它应用于正文,将其应用于如下所示的全尺寸容器,将容器大小和位置设置为绝对,然后将其余内容设置为相对并设置z索引.

?<body>
<div class="bgImageContainer">
</div>
<div class="content"> Some text and stuff here</div>
</body>?????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
.bgImageContainer{
    background-image:url('http://www.whitegadget.com/attachments/pc-wallpapers/16950d1224057972-landscape-wallpaper-blue-river-scenery-wallpapers.jpg'); 
    width:500px;
    height:400px;
    -webkit-filter: blur(5px);
    z-index:0;
    position:absolute;
}
.content{
    z-index:10;
    position:relative;
}
Run Code Online (Sandbox Code Playgroud)

编辑 - 更新了小提琴,旧图像不再工作.

http://jsfiddle.net/Yr2zD/1130/