Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I blur an image using css but keep the border straight?

Tags:

css

image

blur

I am trying to blur an image using CSS. I'm usig "blur" but I'm finding this also blurs the border. Is there a way to keep the border straight but blur the rest of the image?

http://www.inserthtml.com/2012/06/css-filters/

css

filter: filter(value);
-webkit-filter: filter(value);
-moz-filter: filter(value);
-o-filter: filter(value);
-ms-filter: filter(value);
like image 794
sharataka Avatar asked Nov 01 '12 17:11

sharataka


People also ask

How do you add a blur effect to a border in CSS?

Blurred Border If you want to visually blur the border of an element, use a pseudo-element, put it behind the parent element with z-index , apply a transparent border, add the background-clip , filter , and clip-path properties.

How do I blur part of an image in CSS?

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.

How do you blur in CSS?

Syntax. filter: blur(px); To apply a blur effect to the background image, with the blur function use the z-index property to set the stack order of the element, set the width and height 100% to have a full background image.

How does blur work in CSS?

CSS | blur() Function The blur() function is an inbuilt function which is used to apply a blurred effect filter on the image. Parameters: This function accepts single parameter radius which holds the blur radius in form of length. This parameter defines the value of the standard deviation to the Gaussian function.


1 Answers

Try something like this:

HTML:

<div id="container">
   <img id="image" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Benz-velo.jpg/220px-Benz-velo.jpg">
</div>​

CSS:

#image{
   filter: blur(5px);
   -webkit-filter: blur(5px);
   -moz-filter: blur(5px);
   -o-filter: blur(5px);
   -ms-filter: blur(5px);

   margin:-1px;
   padding:1px;
}

#container{
   width:222px;
   height:179px;
   overflow:hidden;
}

The margin on the image seems to be required for some reason (at least in Chrome).

Also on jsfiddle: http://jsfiddle.net/jdwire/HUaBV/1/.

like image 153
Joshua Dwire Avatar answered Sep 20 '22 17:09

Joshua Dwire