Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How CSS draws a semicircle


May 29, 2021 Article blog



The other day, the W3Cschool editor-in-chief taught everyone to draw basic graphics using CSS. S o now we're going to start a new chapter and learn some special graphics. So this article, small editor teaches you how to draw a semicircle with CSS.

Let's take a look at the final effect:

 How CSS draws a semicircle1

source:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>W3Cschool-编程狮</title>
	<style type="text/css">
		#semi-circle{
			width: 200px;
			height: 100px;
			background-color: red;
			border-radius:100px 100px 0 0;/* 左上、右上、右下、左下 */
		}
	</style>
</head>
<body>
	<div id="semi-circle"></div>
</body>
</html>

The example above is to draw an upper half circle, and if you want to draw a semicircle in another direction, you only need to modify the code of border-radius

  • Top half circle: border-radius: 100px100px 0 0;
  • Second half circle: border-radius: 0 0 100px 100px;
  • Left half circle: border-radius: 100px0 0 100px;
  • Right half circle: border-radius:0 100px 100px 0;
That's how CSS draws the whole contents of a semicircle, isn't it super simple?