I am not sure if it is possible as such by im wanting a particular shape as shown in the image below in CSS.
Any help would be appreciated
I am not sure if it is possible as such by im wanting a particular shape as shown in the image below in CSS.
Any help would be appreciated
Yes, you can do with below code. All we are doing is creating a rectangular box with the div
and positioning a circular box (using :before
and border-radius
) on top of it on the left side.
HTML:
<div class='shape'></div>
CSS:
.shape{
height: 100px; /* height of rectangular area */
width: 200px; /* width of rectangular area */
background: red;
margin-left: 50px; /* Just for demo */
}
.shape:before{
position: absolute;
content: '';
height: 100px; /* equal to height of box */
width: 100px; /* equal to height of box because we need a circle */
background: white;
border-radius: 50px; /* 50% of height/width to make a circle */
margin-left: -50px; /* equal to border-radius to move it left by that much */
}
HTML:
<div class='container'>
<span class='shape'></span>
</div>
CSS:
.container{
height: 100px;
width: 100px;
background:red;
position:relative;
margin-top:100px;
margin-left:100px;
}
.shape{
width: 50px;
height: 100px;
top:0px;
left:-50px;
overflow:hidden;
position:absolute;
}
.shape:after{
content:'';
width: 100px;
height: 100px;
border-radius: 100px;
background:rgba(0,0,0,0);
position:absolute;
top:-40px;
left:-90px;
border:40px solid red;
}
(Courtesy King King)
CSS:
div {
width:300px;
height:200px;
overflow:hidden;
position:relative;
left:100px;
top:50px;
}
div:before {
content:'';
position:absolute;
top:0;
left:-100px; /* should be equal to height */
height:100%;
width:200px;/* should be equal to height */
border-radius:50%;
box-shadow:0 0 0 1000px red;
}
Extra Sample: For additional samples, refer this thread.
Simply use a border-radius
on a nested child element. There is nothing to explain as the code is pretty easy, so I think you will figure it out, speaking about this line which is important - border-radius: 0 50% 50% 0;
is a short hand where the values of top-right
and bottom-right
are set to 50%
.wrap {
background: #CC0001;
height: 200px;
width: 600px;
}
.wrap .inner {
height: 200px;
width: 200px;
background: #fff;
border-radius: 0 50% 50% 0;
}
You could use two divs, one rectangle red one and another white one overlayed with css border-radius 100%