Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blur part of an image with CSS

I have a problem with an image. I tried to blur a part of an image, but my solution deosn't work. Please, take a look at this code:

HTML file

<div id="image">
    <div class="blur"></div>
</div>

CSS file

#image {
    width: 940px;
    height: 360px;
    background-image: url('../img/photo.png');
}

#image .blur {
    background-image: url('../img/photo.png');
    background-position: center right;
    -webkit-filter: blur(3px);
    -moz-filter: blur(3px);
    -o-filter: blur(3px);
    -ms-filter: blur(3px);
    filter: blur(3px);
    filter: blur(3px);
    float: right;
    height: 100%;
    width: 360px;
}

It's possible in CSS?

like image 960
user3097025 Avatar asked Oct 08 '14 19:10

user3097025


People also ask

How do I blur part of an image in HTML?

You choose a suitable background-position for the outer div. Make inner div position:absolute . This is where the blur appears. Apply blur to the :before selector.

Can we blur image with CSS?

In CSS, filter property is used to convert an image into blur image. Filter property is mainly used to set the visual effect of an image. Example 1: This example use blur filter to convert the image into blur image.


2 Answers

I have set the overflow property of the outer div to hidden and the margin-right of the inner one to -1 and it worked like a charm.

#image {
    ...
    overflow: hidden;
}

#image .blur {
    ...
    margin-right: -1px;
}

Here is the working example in JSFiddle.

#image {
    width: 940px;
    height: 360px;
    overflow: hidden;
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Nuvola_wikipedia_icon.png/240px-Nuvola_wikipedia_icon.png');
}

#image .blur {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Nuvola_wikipedia_icon.png/240px-Nuvola_wikipedia_icon.png');
    background-position: center right;
    -webkit-filter: blur(3px);
    -moz-filter: blur(3px);
    -o-filter: blur(3px);
    -ms-filter: blur(3px);
    filter: blur(3px);
    filter: blur(3px);
    float: right;
    height: 100%;
    width: 360px;
    margin-right: -1px;
}
<div id="image">
    <div class="blur"></div>
</div>
like image 104
Karlen Kishmiryan Avatar answered Oct 14 '22 08:10

Karlen Kishmiryan


You choose a suitable background-position for the outer div.

Make inner div position:absolute. This is where the blur appears. Apply blur to the :before selector.

JSFiddle Demo

like image 37
Srinivasan Avatar answered Oct 14 '22 09:10

Srinivasan