Slick effects with CSS3 box-shadow


Drop shadows and inner shadows are some of the effects I learned to apply using Photoshop’s Blending options. But now, since CSS3 “hit the charts”, you don’t need Adobe’s design tool to add a drop shadow or an inner shadow to a box.

Nowadays, the cool thing is that you create beautiful CSS3 shadows without actually needing Photoshop anymore.

box-shadow property

The box-shadow property allows you to add multiple shadows (outer or inner) on box elements. To do that you must specify values as: color, size, blur and offset.

box-shadow: inset(optional)3px 3px 10px 5px #000;

box-shadow: inset horizontal offset vertical offset blur radius speed distance color;

  • A positive value for the horizontal offset draws a shadow that is offset to the right of the box, a negative
    length to the left.
  • The second length is the vertical offset. A positive value for the vertical offset basically offsets the
    shadow down, a negative one up.
  • You’re not allowed to use negative values for blur radius. The larger
    the value, the more the shadow’s edge is blurred, as it can be seen above.
  • Spread distance positive values cause the
    shadow shape to expand in all directions by the specified radius.
    Negative ones cause the shadow shape to contract.
  • The color is the color of the shadow.
  • The inset keyword, if present,
    changes the drop shadow from an outer shadow to an inner
    shadow

Example

<!doctype html>
<html lang="en">
<head>
	<title>Slick effects with CSS3 box-shadow</title>
<style>
	body{
		background: #fff;
	}
	.myBox{
		position: relative;
		width: 30%;
		background: #ddd;
		border-radius: 4px;
		padding: 2em 1.5em;
		color: #000;
		text-shadow: 0 1px 0 #fff;
		line-height: 1.5;
		margin: 60px auto;
	}
	.myBox:before, .myBox:after 
	{
	  z-index: -1; 
	  position: absolute; 
	  content: "";
	  bottom: 15px;
	  left: 10px;
	  width: 50%; 
	  top: 80%;
	  max-width:300px;
	  background: rgba(0, 0, 0, 0.7); 
	  -webkit-box-shadow: 0 15px 10px rgba(0,0,0, 0.7);   
	  -moz-box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
	  box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
	  -webkit-transform: rotate(-3deg);    
	  -moz-transform: rotate(-3deg);   
	  -o-transform: rotate(-3deg);
	  -ms-transform: rotate(-3deg);
	  transform: rotate(-3deg);
	}

	.myBox:after 
	{
	  -webkit-transform: rotate(3deg);
	  -moz-transform: rotate(3deg);
	  -o-transform: rotate(3deg);
	  -ms-transform: rotate(3deg);
	  transform: rotate(3deg);
	  right: 10px;
	  left: auto;
	}	
</style>
</head>
<body>
	<div class="myBox"> 
	sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text
	</div>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s