Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS blur on background image but not on content [duplicate]

I did this example.

I'm trying to blur the background image, but the main content is blurred too (the <span>)

How can I blur the background without blurring the content?

like image 751
itsme Avatar asked Dec 05 '13 21:12

itsme


People also ask

How do you blur the background of a picture without the content?

You can blur the body background image by using the body's :before pseudo class to inherit the image and then blurring it. Wrap all that into a class and use javascript to add and remove the class to blur and unblur.

How do I blur the background of an image in CSS?

You have to blur the whole element in order to blur the background. So if you want to blur only the background, it has to be its own element. Show activity on this post. The following is a simple solution for modern browsers in pure CSS with a 'before' pseudo element, like the solution from Matthew Wilcoxson.

Can you blur the background in post production?

Post-production BlurIf you really want to emphasize the subject, the whole background can be blurred the same amount. If you're looking for a little bit more authenticity, you can blur what's furthest away more and gradually lessen the blur as you get closest.


3 Answers

jsfiddle

.blur-bgimage {
    overflow: hidden;
    margin: 0;
    text-align: left;
}
.blur-bgimage:before {
    content: "";
    position: absolute;
    width : 100%;
    height: 100%;
    background: inherit;
    z-index: -1;

    filter        : blur(10px);
    -moz-filter   : blur(10px);
    -webkit-filter: blur(10px);
    -o-filter     : blur(10px);

    transition        : all 2s linear;
    -moz-transition   : all 2s linear;
    -webkit-transition: all 2s linear;
    -o-transition     : all 2s linear;
}

You can blur the body background image by using the body's :before pseudo class to inherit the image and then blurring it. Wrap all that into a class and use javascript to add and remove the class to blur and unblur.

like image 174
Mike Lee Avatar answered Oct 24 '22 17:10

Mike Lee


You could overlay one element above the blurred element like so

DEMO

div {
    position: absolute;
    left:0;
    top: 0;
}
p {
    position: absolute;
    left:0;
    top: 0;
}
like image 32
Kevin Lynch Avatar answered Oct 24 '22 18:10

Kevin Lynch


Add another div or img to your main div and blur that instead. jsfiddle

.blur {
    background:url('http://i0.kym-cdn.com/photos/images/original/000/051/726/17-i-lol.jpg?1318992465') no-repeat center;
    background-size:cover;
    -webkit-filter: blur(13px);
    -moz-filter: blur(13px);
    -o-filter: blur(13px);
    -ms-filter: blur(13px);
    filter: blur(13px);
    position:absolute;
    width:100%;
    height:100%;
}
like image 25
TreeTree Avatar answered Oct 24 '22 19:10

TreeTree