Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div with a transparent cut out circle [duplicate]

Tags:

css

css-shapes

Can I make a rectagle div with a half cut out circle using CSS? The half circle should be transparent and let the background show through.

desired CSS shape :

square div with a transparent cut out half circle

HTML :

<div></div>

CSS :

div{
    background : #448CCB;
    width:300px;
    height:300px;
}
like image 210
Aeon Wallace Avatar asked Jul 15 '14 10:07

Aeon Wallace


2 Answers

In order to have the white cut out circle transparent and let the background show through it, you can use box-shadows on a pseudo element to minimize markup.

In the following demo, the blue color of the shape is set with the box shadow and not the background-color property.

DEMO

output:

Div with cut out half-circle

This can also be responsive: demo

HTML:

<div></div>

CSS:

div {
  width: 300px;
  height: 300px;
  position: relative;
  overflow: hidden;
}

div::before {
  content: '';
  position: absolute;
  bottom: 50%;
  width: 100%;
  height: 100%;
  border-radius: 100%;
  box-shadow: 0px 300px 0px 300px #448CCB;
}
like image 191
web-tiki Avatar answered Oct 13 '22 16:10

web-tiki


Is it okey ?

Demo

div{
    width:100px;
    height:100px;
    background:#03b0d5;
    display:block;
    position:relative;
    overflow:hidden;
}
div:after{
    width:100px;
    height:100px;
    border-radius:50%;
    background:#fff;
    display:block;
    position:absolute;
    content:'';
    top:-50px;
    left:0;
 }
like image 1
ShibinRagh Avatar answered Oct 13 '22 16:10

ShibinRagh