Effect How to - Create paper edge like shadow with box-shadow








Question

We would like to know how to create paper edge like shadow with box-shadow.

Answer


<!DOCTYPE html>
<html>
<head>
  <style type='text/css'>
  body:before <!--   w  w  w.ja  v a 2 s .co m-->
  {
    content: "";
    position: fixed;
    top: -10px;
    left: 0;
    width: 100%;
    height: 10px;
    z-index: 100;
    -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
    -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
    box-shadow: 0px 0px 10px rgba(0,0,0,.8);        
  }
  #box 
  {
    position: relative;
    width: 60%;
    background: #ddd;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding: 2em 1.5em;
    color: rgba(0,0,0, .8);
    text-shadow: 0 1px 0 #fff;
    line-height: 1.5;
    margin: 60px auto;
  }
  #box:before, #box: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);
  }
  #box: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 id="box">
        <h1>java2s.com</h1>
        <p>this is a test</p>
    </div>
</body>
</html>

The code above is rendered as follows: