Transparent half circle cut out of a div

2018-12-31 15:56发布

I would like to make a transparent cut out half circle shape using only CSS3. The only requirement is that all the elements that form the shape must be black or transparent.

I cannot use a black rectangle with a white circle on top of it because the half circle has to be transparent and let the background show through.

Desired shape :

rectangle with cut out half circle

7条回答
一个人的天荒地老
2楼-- · 2018-12-31 16:40

May be can do it with CSS :after pseudo property like this:

.rect
{
    height: 100px;
    width: 100px;
    background:rgba(0,0,0,0.5);
    position:relative;
    margin-top:100px;
    margin-left:100px;
}
.circle{
    display:block;
    width: 100px;
    height: 50px;
    top:-50px;
    left:0;
    overflow:hidden;
    position:absolute;
}
.circle:after{
    content:'';
    width: 100px;
    height: 100px;
    -moz-border-radius: 100px;
    -webkit-border-radius: 100px;
    border-radius: 100px;
    background:rgba(0,0,0,0);
    position:absolute;
    top:-100px;
    left:-40px;
    border:40px solid rgba(0,0,0,0.5);
}

http://jsfiddle.net/FcaVX/2/

查看更多
登录 后发表回答