Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropshadow with css

I want to add a transparent dropshadow to my div. I have a container, and behind it I want to place a dropshadow. I don't want the dropshadow to have a color. This is what I have so far:

.content_right1{

    background:#fff;

    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
     border-radius:10px;

    -moz-box-shadow: 5px 5px 5px #99CCFF;
    -webkit-box-shadow: 5px 5px 5px #99CCFF ;
     box-shadow: 5px 5px 5px #99CCFF;

    /* other styles of the class */
    width:380px;
    float:left;

    margin-left:3px;
    padding:15px;

    min-height:450px;
    margin-left:15px;
}

I want to add the opacity, but when I do the opacity of the whole div changes.

like image 525
user952691 Avatar asked Oct 02 '11 14:10

user952691


People also ask

What does box shadow do in CSS?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.

Can you add shadow to an image in CSS?

With CSS you can create shadow effects!

How does text-shadow work in CSS?

The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations . Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color.


2 Answers

If you want a dropshadow with a level of opacity, you should use rgba() for its shadow color :

http://css-tricks.com/2151-rgba-browser-support/

edit:

-moz-box-shadow:5px 5px 5px rgba(0,0,0,0.3);
-webkit-box-shadow:5px 5px 5px rgba(0,0,0,0.3);
box-shadow:5px 5px 5px rgba(0,0,0,0.3);
like image 108
Darklg Avatar answered Sep 24 '22 08:09

Darklg


While your question is ultimately a little opaque (pun intended), does the following do what you are expecting?

-moz-box-shadow: 5px 5px 5px #dddddd;
-webkit-box-shadow: 5px 5px 5px #dddddd;
box-shadow: 5px 5px 5px #dddddd;

http://jsfiddle.net/zCTC8/2/

All I essentially did was adjust the color value of the shadow, which is the last value in the declaration (#dddddd, or #ddd). These are hex values. See here for more examples:

http://html-color-codes.com/

#ddd/#dddddd represents a light grey color; #eee is lighter, #ccc is darker, #fff is white, and #000 is black. The value #000 represents RGB, with valid values of 0-9A-F (dark->light), so that:

#f00 = red (R)
#0f0 = green (G)
#00f = blue (B)

The value #99CCFF from your question is equivalent to #9CF, which gives a middle red (9), a light green (C), and white (F). The mix of these values gives you the light blue shade you were seeing, which is why you were getting a color instead of a "shadow-like" color (gray shade).

My color theory is a little rusty here, so anyone correct me if I've flubbed something.

like image 25
Jared Farrish Avatar answered Sep 24 '22 08:09

Jared Farrish