css - 模糊图像导致从容器/div 外部吸收元素

标签 css blur

<分区>

I have this very simple pen of a blurred background image.

HTML

<div> </div>

CSS

div {
  background: url(http://s15.postimg.org/4elomwgbv/luxvitae.jpg) no-repeat;
  width: 1500px;
  height: 1000px;
  -webkit-filter: blur(25px); 
  -moz-filter: blur(5px); 
  -o-filter: blur(5px); 
  -ms-filter: blur(5px); 


     filter: blur(5px);
    }

body{
  background-color: green;
}

现在发生的是模糊实际上考虑了周围或位于下方的元素,这是我不喜欢的

enter image description here

它基本上是在不应该有背景的地方显示背景,并将图像模糊到背景中。我想要看到的是:没有绿色重叠到我的 div 容器中。我的 div 应该只包含模糊的图像。

有人有想法吗?

最佳答案

这是因为模糊也会使边缘羽化。您可以使用伪元素将模糊图像叠加在图像之上,但由于显而易见的原因边缘不会模糊。

示例(点击“整页”按钮):

.blurimg {
  background: url(http://s15.postimg.org/4elomwgbv/luxvitae.jpg) no-repeat;
  width: 1500px;
  height: 1000px;
  position: relative;
}
.blurimg:after {
  content: '';
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: inherit;
  -webkit-filter: blur(5px); 
  -moz-filter: blur(5px); 
  -o-filter: blur(5px); 
  -ms-filter: blur(5px); 
  filter: blur(5px);
}

body{
  background-color: green;
  margin: 0;
}
<div class="blurimg"> </div>

关于css - 模糊图像导致从容器/div 外部吸收元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27932766/

相关文章:

html - 超大屏幕高度和 float

ios - 在iOS5设备上测试Flash应用程序时模糊效果消失

jquery - 内联编辑: onBlur prevents onClick from being triggered (jQuery)

ipad - 在 UIWebView 中运行 HTML5/CSS3

css - 单击时可以将文本颜色更改为#000000 的命令是什么

jquery - 如何实现这样的连续视差?

javascript - 如何显示弹出窗口

css - 图像右边缘淡化/模糊 CSS

html - 模糊背景图像缩小它,如何在不缩小的情况下模糊?

image-processing - 低质量相机的模糊内核