I have a JPEG file that I'm using as a background image for my search page, and I'm setting it up using CSS because I'm working in a Backbone.js context:
background-image: url("whatever.jpg");
I want to apply a CSS 3 blur filter to only the background, but I'm not sure how to style just that element. If I try:
-webkit-filter: blur(5px); -moz-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); filter: blur(5px);
Place the above code in my CSS under background-image
and it will style the entire page, not just the background. Is there a way to select just an image and apply a filter to that image? Alternatively, is there a way to just turn off the blur effect for other elements on the page?
pen
Does away with the need for extra elements, allowing content to fit into the document flow rather than being fixed/absolute like other solutions.
Use the following methods to achieve
EditIf you want to remove the white border at the edges, use
110%
for width and height and-5%
for left and top. This will slightly enlarge your background image, but won't have solid color bleeding through the edges. Thanks to Chad Fawcett for the suggestion.View thisNotebook.
You will need to use two different containers, one for the background image and another for the content.
In the example, I created two containers,
.background-image
and.content
.They all use
position: fixed
andleft: 0; right: 0;
for positioning. The difference in their display comes from the differentz-index
values set for the elements.