CSS3 now provides us with the
box-shadow
property, which
can be used to create multiple shadows on any block level element
programmatically. This saves a lot of time spent in image editing
software and removes those nasty nested divs, but it isn't supported by
Internet Explorer, so what is best for us to do?
Browser support is growing of late with Mozilla (Firefox), Webkit
(Safari/Chrome/Konqueror), Opera and the IE9 Platform Preview all
offering a decent implementation of the spec, although Mozilla and
Webkit still require their respective
-moz-
and
-webkit-
prefixes (note Mozilla Firefox 4.0+ no longer requires the
-moz-
prefix).
Used in casting shadows off block-level elements
.shadow {
-moz-box-shadow: 3px 3px 5px 6px #ccc;
-webkit-box-shadow: 3px 3px 5px 6px #ccc;
box-shadow: 3px 3px 5px 6px #ccc;
}
Syntax :
box-shadow: h-shadow v-shadow blur spread color inset;
- h-shadow : The horizontal offset of the shadow, positive means
the shadow will be on the right of the box, a negative offset will put
the shadow on the left of the box.
- v-shadow :The vertical offset of the shadow, For above the box use negative and for below use positive.
- blur :The blur radius (optional), if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be.
- spread :The spread radius (optional), positive values
increase the size of the shadow, negative values decrease the size.
Default is 0 (the shadow is same size as blur).
- color : (optional) The color of the shadow.
- inset : (optional) Changes the shadow from an outer shadow (outset) to an inner
shadow
Example :1
div#myDIV
{
background-color:orange;
width:200px;
height:100px;
box-shadow:10px 10px black;
}
Example :2
div#myDIV
{
background-color:orange;
width:200px;
height:100px;
box-shadow:20px 20px 10px black;
}
This all the CSS for various web browser collected in one rule:
.shadow {
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 4px #000;
box-shadow: 3px 3px 4px #000;
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
Read more →