CS - BOX SHADOWS

giving a 3-D effect to block-level elements, cool...


Code Library »

The Finished Product

Used to cast shadows off block-level elements (like divs).

Ex. 1 - Bottom Right
Ex. 2 - Top Left
Ex. 3 - Inset
Ex. 4 - Single Sided
Shadow - BONUS 1
Shadow - BONUS 2

Update:

All major web browsers, [ Chrome, Safari, Firefox, Opera and IE9+ ], will now work with standard CSS call: box-shadow: 2px 3px 4px 5px #222222;. The prefixes are no longer needed.

How It's Done

There are 5 properties that can be used when adding shadows. Three are required and two others are optional:

Box-Shadow Properties

Horizontal Offset (required)
A positive offset value will put the shadow on the right of the box, a negative offset will put the shadow on the left of the box.
Vertical Offset (required)
A positive offset will put the shadow below the box and a negative offset will place the shadow at the top.
Color (required)
You can use rgba values: rgba(0,0,0,0.4); or hex values: #222222; and even color names: darkblue;.
Blur Radius (optional)
A value of 0, zero will produce a sharp or well defined shadow. The higher the number, the more blur is added to the shadow.
Spread Radius (optional)
Positive values increase the size o fthe shadow where negative values decrease the size. The default is 0, zero meaning, (the shadow is the same size as the blur).

CSS Box-Shadow Settings - see EXAMPLE 1

.box-shadow ex1 {
	-webkit-box-shadow: 3px 3px 8px 1px #222222;
	-moz-box-shadow: 3px 3px 8px 1px #222222;
	box-shadow: 3px 3px 8px 1px #222222;
}
                    

CSS Box-Shadow Settings - Using negative values. see EXAMPLE 2

.box-shadow ex2 {
	-webkit-box-shadow: -3px -3px 8px 1px #222222;
	-moz-box-shadow: -3px -3px 8px 1px #222222;
	box-shadow: -3px -3px 8px 1px #222222;
}
                    

CSS Box-Shadow Settings - Inner Shadow. see EXAMPLE 3

.box-shadow ex3 {
	-webkit-box-shadow: inset 0px 0px 20px #222222;
	-moz-box-shadow: inset 0px 0px 20px #222222;
	box-shadow: inset 0px 0px 20px #222222;
}
                    

CSS Box-Shadow Settings - Single Sided. see EXAMPLE 4

.box-shadow ex4 {
	-webkit-box-shadow: 0px 8px 6px -6px #222222;
	-moz-box-shadow: 0px 8px 6px -6px #222222;
	box-shadow: 0px 8px 6px -6px #222222;
}
                    

CSS Box-Shadow Settings - Bonus 1

.box-shadow.curls {
    width: 200px;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
    position: relative;
}
.box-shadow.curls:before,
.box-shadow.curls:after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 0px;
    right: auto;
    height: 6px;
    width: 50%;
    box-shadow: 0 10px 12px rgba(0, 0, 0, 0.65);
    transform: skew(-4deg) rotate(-4deg);
    z-index: -1;
}
.box-shadow.curls:after {
	transform: skew(4deg) rotate(4deg);
	left: auto;
	right: 0px;
}
                    

CSS Box-Shadow Settings - BONUS 2

.box-shadow bonus {
	height: 120px;
	width: 120px;
	background-color: #ff9933;
	border: 10px solid #3377bb;
	border-radius: 50%;
	box-shadow: 6px 6px 20px 4px rgba(0,0,0,0.345),
            8px 10px 0px 18px rgba(0,0,0,0.575) inset;
}