1. 圆形
思路: 先准备一个正方形,让border-radius(半径)为高度/宽度的一半即可。
1.1 代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.circle {
background-color: pink;
width: 200px;
height: 200px;
/* 设置为高度/宽度的一半 */
border-radius: 100px;
}
</style>
</head>
<body>
<div class="circle"></div>
</body>
</html>
1.2 结果
2. 圆角矩形
思路: 让border-radius为高度的一半即可
2.1 代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.juxing {
width: 200px;
height: 50px;
background-color: yellowgreen;
/* 设置为高度的一半 */
border-radius: 25px;
}
</style>
</head>
<body>
<div class="juxing"></div>
</body>
</html>
1.2 结果
3. 不同圆角的设置
border-radius顺序:左上角、右上角、右下角、左下角
3.1 代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.radius {
background-color: skyblue;
width: 200px;
height: 180px;
border-radius: 20px 50px 20px 50px;
}
</style>
</head>
<body>
<div class="radius"></div>
</body>
</html>