css案列,通过伪类元素实现盒子阴影效果

用伪类元素给盒子添加阴影效果。

   body{
            background-color: #eee;
        }
        div{
            width: 200px;
            height: 200px;
            margin: 100px;
            background-color: #fff;
            padding: 10px 50px;
        }
        .box1{
            transition: all 0.5s;
            
        }
        .box1:hover{
            box-shadow: 0 0 10px 0 rgba(0,0,0,0.3);
        }
        .box2{
            position: relative;
            background-color: #fff;
        }
        .box2::before{
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            box-shadow: 0 0 10px 0 rgba(0,0,0,0.3);
            z-index: -1;
            transition: 0.3s;
            opacity: 0;
        }
        .box2:hover:before{
            opacity: 1;
        }

 

posted @ 2020-09-15 08:40  MyKai  阅读(304)  评论(0)    收藏  举报