Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft Edges using CSS?

Tags:

css

I am using RGBA to create a transparent background that overlays on top of an image. Works just fine. My questions is this: Is there a way to "soften" the edges of the box to where it flows more into the picture vs a hard edge.

Here is my CSS for the box:

#past{     position:absolute;     left:0;     top:363px;     background-color: rgba(34,34,34,0.6);     /* For IE 5.5 - 7*/     filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99222222, endColorstr=#99222222);     /* For IE 8*/     -ms-filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99222222, endColorstr=#99222222);     z-index:10;     padding:10px; } 

I know I can do this by creating a background image in Photoshop but I was looking for a CSS only way vs using an image.

Also I would prefer if at all possible for this to work in all browsers.

Thanks for the help. =>

like image 277
L84 Avatar asked Aug 06 '11 04:08

L84


People also ask

How do you soften a border in CSS?

Positive numbers shift it right, negative left. 2px: Vertical offset of the effect. Positive numbers shift it down, negative up. 3px: The blur effect.

How do I soften the edges of an image in CSS?

If what you're looking for is simply to blur the image edges you can simply use the box-shadow with an inset. With CSS it's possible to create a circle. Just use "border-radius:50%". The above method for creating an image soft edge does not appear to work with 'circle' images.

How do I blur edges in CSS?

Blurring the edges of a photo in CSS is pretty straightforward, with one gotcha. To blur a photo we need to use box-shadow in a way where the shadow "eats" the image. For this effect to work, the blur must be the same color as the surrounding background, and inset must be used.


1 Answers

Another option is to use one of my personal favorite CSS tools: box-shadow.

A box shadow is really a drop-shadow on the node. It looks like this:

-moz-box-shadow: 1px 2px 3px rgba(0,0,0,.5); -webkit-box-shadow: 1px 2px 3px rgba(0,0,0,.5); box-shadow: 1px 2px 3px rgba(0,0,0,.5); 

The arguments are:

1px: Horizontal offset of the effect. Positive numbers shift it right, negative left. 2px: Vertical offset of the effect. Positive numbers shift it down, negative up. 3px: The blur effect.  0 means no blur. color: The color of the shadow. 

So, you could leave your current design, and add a box-shadow like:

box-shadow: 0px -2px 2px rgba(34,34,34,0.6); 

This should give you a 'blurry' top-edge.

This website will help with more information: http://css-tricks.com/snippets/css/css-box-shadow/

like image 152
OverZealous Avatar answered Oct 09 '22 00:10

OverZealous