I have a JPEG file that I'm using as a background image for a search page, and I'm using CSS to set it because I'm working within Backbone.js contexts:
background-image: url("whatever.jpg");
I want to apply a CSS 3 blur filter only to the background, but I'm not sure how to style just that one element. If I try:
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
just underneath background-image
in my CSS, it styles the whole page, rather than just the background. Is there a way to select just the image and apply the filter to that? Alternatively, is there a way to just turn the blur off for every other element on the page?
I didn't write this, but I noticed there was a polyfill for the partially supported
backdrop-filter
using the CSS SASS compiler, so if you have a compilation pipeline it can be achieved nicely: (also uses typescript)https://codepen.io/mixal_bl4/pen/EwPMWo
all you actually need is "filter: blur(≪WhatEverYouWantInPx≫);"
Just letting pep's know, if this already wasn't said. If you want to content to be scrollable, set the position of the content to absolute:
I don't know if this was just for me, but if not that's the fix!
Also since the background is fixed, it means you have a 'Parallax' effect! So know not only did this person teach you how to make a blurry background, but also a parallax background effect!
Check out this pen.
You will have to use two different containers, one for the background image and the other for your content.
In the example, I have created two containers,
.background-image
and.content
.Both of them are placed with
position: fixed
andleft: 0; right: 0;
. The difference in displaying them comes from thez-index
values which have been set differently for the elements.HTML
CSS
Apologies for the Lorem Ipsum Text.
Update
Thanks to Matthew Wilcoxson for a better implementation using
.content:before
http://codepen.io/akademy/pen/FlkzBpen
Abolishing the need for an extra element, along with making the content fit within the document flow rather than being fixed/absolute like other solutions.
Achieved using
Overflow auto is needed, else the background will be offset by a few pixels at the top.
After this you simply need
EDIT If you are interested in removing the white borders at the edges, use a width and height of
110%
and a left and top of-5%
. This will enlarge your backgrounds a tad - but there should be no solid colour bleeding in from the edges.Updated Pen here: https://codepen.io/anon/pen/QgyewB - Thanks Chad Fawcett for the suggestion.
In the
.content
tab in CSS change it toposition:absolute
. Otherwise, the page rendered won't be scrollable.