CSS pseudo-class before after implementation stereo effect

Source: Internet
Author: User
div {width:200px;    height:200px;    border:1px solid #ccc;    position:relative;    Background-color: #fff;    Float:left;    Text-align:center; margin:30px;}.    Div1::after {z-index:-15;    Position:absolute;    Content: "";    bottom:14px;    right:7px;    width:36%;    top:59%;    max-width:300px;    Background: #777;    box-shadow:0 15px 10px #A5A5A5; -webkit-transform:rotate (3deg);}.    Div1::before {z-index:-15;    Position:absolute;    Content: "";    bottom:14px;    left:6px;    width:36%;    top:59%;    max-width:300px;    Background: #777;    box-shadow:0 15px 10px #A5A5A5; -webkit-transform:rotate ( -3deg);}.    div2 {border-bottom-right-radius:50px; Box-shadow: -1px 2px 2px rgba (0, 0, 0, 0.2);}.    Div2::after {content: ';    width:22px;    height:22px;    Position:absolute;    bottom:0px;    right:0px;    border-radius:0 0 16px 0;    Box-shadow: -2px-2px 5px Rgba (65, 65, 65, 0.38); -webkit-transform:rotate ( -20deg) skew (-40DEG,-3DEG) translate ( -10px,-10px);}. Div3 {border-radius:60px/5px;}.    Div3::after {z-index:-15;    Position:absolute;    Content: "";    bottom:2px;    left:4%;    width:91%;    height:10px;    max-width:300px;    Background: #777;    box-shadow:0px 4px 11px 1px #A5A5A5; border-radius:50%;}.    Div3::before {z-index:-15;    Position:absolute;    Content: "";    left:4%;    width:91%;    height:10px;    top:4px;    max-width:300px;    Background: #777;    box-shadow:0px-4px 11px 1px #A5A5A5; border-radius:50%;}
<div class= "Div1" >123</div>    <div class= "Div2" >123</div>    <div class= "Div3" > 123</div>

http://jsfiddle.net/N93a3/

Summarize:

If you use before or after you must assign a content property to it, it is empty to show the effect. A div that uses pseudo-classes is generally set to position:relative, and pseudo-class elements are generally set to Position:absolute. The effect of shadowing is generally based on the Box-shaw attribute of the pseudo-class element, which is generally set behind the div and is blocked by it. Div's Border-radius can be set to Xxpx/xxpx to get unexpected results.

  • 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.