剪切圆形框阴影,它与正方形<div>重叠

时间:2015-09-24 22:57:47

标签: css

考虑以下内容 -

int[]
#banner {
    width: 100%;
    height: 50px;
    box-shadow: 0 0 10px #000000;
    background: #63B0F2;
}

#circle {
    position: relative;
    top: 20px;
    height: 80px;
    width: 80px;
    margin: 0 auto;
    border-radius: 50%;
    box-shadow: 0 0 10px #000000;
    background-color: white;
}

是否可以将白色方块上半部投射的阴影移除/剪裁到蓝色div上?

换句话说,只有阴影投射到背景上,而不是彼此?

1 个答案:

答案 0 :(得分:0)

伪元素:before:after的可能解决方案。只需添加到您的CSS:

#circle:before{
    position: absolute;
    content: "";
    width: 150%;
    height: 50%;
    left: -25%;
    top: -10px;
    background: #63B0F2;
}

#circle:after{
    position: absolute;
    content: "";
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: white;
    border-radius: 50%;
}

DEMO