Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a semicircle with CSS when the height and width are percentages? [duplicate]

Tags:

html

css

How do I draw a semicircle with CSS when the height and width are percentages?

.container{
  width: 200px;
  height: 200px;
  background: blue;
  display: flex;
}

.semiCircle{
  position:relative;
  height: 90%;
  width: 45%;
  border-radius: 90% 0 0 90%;
  background: red;
  margin:auto;
}
<div class='container'>
  <div class='semiCircle'></div>
</div>
like image 806
Miao Avatar asked Nov 20 '20 09:11

Miao


People also ask

How do you make a semi circle in CSS?

You could use border-top-left-radius and border-top-right-radius properties to round the corners on the box according to the box's height (and added borders). Then add a border to top/right/left sides of the box to achieve the effect.

How do you make a half circle background in CSS?

To create left-semi-circle, height should be double of width. top-left corner and bottom-left corner of border-radius should be 0. top-right corner and bottom-right corner of border-radius should equal to width.

How do you cut a circle in half CSS?

This can be done purely on CSS making use of borders. Keep note that height has to be half of the width to give the half circle. border-top-left or right-radius is the thing that adds the curve. So adding that extra +10 to it makes up for the space the border(which is set to 10px) creates.

How do you draw an arc in CSS?

CSS Shapes It's possible to draw circles and arcs in CSS by simply creating a square <div> and setting border-radius to 50%. Each side of the border can take a different color or can be set to transparent . The background-color property sets the shape's fill, if any.


1 Answers

First, create a circle with border-radius: 100%;. Then, make half of it transparent with background: linear-gradient(90deg, red 50%, transparent 50%);.

.container {
  width: 200px;
  height: 200px;
  background: blue;
  display: flex;
}
.semiCircle {
  height: 90%;
  width: 45%;
  border-radius: 100%;
  margin: auto;
  background: linear-gradient(90deg, red 50%, transparent 50%);
}
<div class='container'>
  <div class='semiCircle'></div>
</div>
like image 85
83C10 Avatar answered Nov 15 '22 12:11

83C10