I am having trouble applying a blur effect on a semi-transparent overlay div. I'd like everything behind the div the be blurred, like this:
Here is a jsfiddle which doesn't work: http://jsfiddle.net/u2y2091z/
Any ideas how to make this work? I'd like to keep this as uncomplicated as possible and have it be cross-browser. Here is the CSS I'm using:
#overlay {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background:black;
background:rgba(0,0,0,0.8);
filter:blur(4px);
-o-filter:blur(4px);
-ms-filter:blur(4px);
-moz-filter:blur(4px);
-webkit-filter:blur(4px);
}
Here is an example that uses
svg
filter.The idea is to use an
svg
element withheight
same as the#overlay
and apply thefeGaussianblur
filter on it. This filter is applied on ansvg
image
element. To give it an extruded effect, you could use abox-shadow
at the bottom of the overlay.Browser Support for
svg
filters.Demo on Codepen
Here's a possible solution.
HTML
CSS
I know the CSS can be simplified and you probably should get rid of the ids. The idea here is to use a div as a cropping container and then apply blur on duplicate of the image. Fiddle
To make this work in Firefox, you would have to use SVG hack.
Thank you for the help everyone! I was able to piece together information from everyone here and from further Googling, and I came up with the following which works in Chrome and Firefox: http://jsfiddle.net/u2y2091z/12/. I'm still working on making this work for IE and Opera.
The key is putting the content inside of the div to which the filter is applied:
And then the CSS:
So mask has the filters applied. Also note the use of url() for a filter with an
<svg>
tag for the value -- that idea came from http://codepen.io/AmeliaBR/pen/xGuBr. If you happen to minify your CSS, you might need to replace any spaces in the SVG filter markup with "%20".So now, everything inside the mask div is blurred.
If you're looking for a reliable cross-browser approach today, you won't find a great one. The best option you have is to create two images (this could be automated in some environments), and arrange them such that one overlays the other. I've created a simple example below:
Though effective, even this approach isn't necessarily ideal. That being said, it does yield the desired result.