整体思路: 太极有三个元素, 大圆,两个小圆.
- 有三个内容为空的border矩形
- 一大: 默认内容为空, 就只剩下白色背景, 然后右边加一个一样大的黑色border
- 二小: 一上一下放在大圆的上下两个鱼眼处
- 默认内容为空, 白色背景是中间的小圆, 背景是黑色
- 默认内容为空, 黑色背景是中间的小圆, 背景是白色
- 太极是圆的啊, 所以把矩形变成圆形的神奇属性:border-radius.
- 设置三个圆的相对位置, 半径大小加起来要要严丝合缝.
代码内容:
- HTML: 一个div
- CSS: 包含三个内容,对应三个圆
- 每行代码都有注释..
- 看不懂快戳评论告诉我!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color:grey;
}
.yinyang {
width: 120px; height: 240px;
background-color: white;
border-color: black;
border-style: solid;
border-width: 1px 121px 1px 1px;
border-radius: 50%;
position: relative;
}
.yinyang:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
background-color: white;
border: 40px solid black;
border-radius: 50%;
width: 40px;
height: 40px;
}
.yinyang:after {
content: "";
position: absolute;
top: 0;
left: 50%;
background-color: black;
border: 40px solid white;
border-radius:50%;
width: 40px;
height: 40px;
}
</style>
</head>
<body>
<div class="yinyang"></div>
</body>
</html>
复制代码