How to make a three-dimensional effect with CSS3 shadow effect

Source: Internet
Author: User
two CSS3 properties used: Box-shadow, transform, basic syntax:

Box-shadow

box-shadow:5px 2px 6px #000;
Values are left-to-right: Shadow horizontal offset value (positive value right, negative value left), Shadow vertical offset value (positive downward, negative value up), shadow blur value, Shadow color.

Transform
The transform has a lot of effects and only rotates here:

Transform:rotate ( -3DEG)
Numeric values represent the angle of rotation, positive values are clockwise, and negative values are counterclockwise.
Because CSS3 is still a draft, the latest version of the existing browser is to support transform with a private attribute, need to add-webkit-、-moz-、-o-、-ms-

Concrete implementation of the idea: in order to highlight the three-dimensional, to let the shadow around the middle light, here used:: Before,::after pseudo-elements, create and let them positioned after the #demo element (z-index:-1), while setting the shadow, and set the rotation, the idea with a picture to represent this:

This is the effect we want, the specific code to see:

Css

 #demo {display:inline-block; position:relative; margin:50px; padding:20px; background: #fafafa; box-shadow:0 0 3px rgba (0, 0, 0, 0.2); -moz-border-radius:4px; border-radius:4px; Color:rgba (0,0,0, 0.8); text-shadow:0 1px 0 #fff;} #demo:: Before, #demo:: after{position:absolute; content: ""; top:10px; bottom:15px; left:10px; width:50%; box-shadow:0 15px 10px rgba (0, 0, 0, 0.5); -webkit-transform:rotate ( -3DEG); -moz-transform:rotate ( -3DEG); -o-transform:rotate ( -3DEG); -ms-transform:rotate ( -3DEG); Transform:rotate ( -3DEG); Z-index:-1;} #demo:: after{right:10px; left:auto;-webkit-transform:rotate (3deg);-moz-transform:rotate (3deg);-o-transform:  Rotate (3deg);  -ms-transform:rotate (3DEG); Transform:rotate (3DEG); } #demo img{vertical-align:bottom;} 

Html

<p id= "Demo" >    </p>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.