提示:巧用伪元素before、after 和box-shadow。
第一步,设置一个div盒子;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/taiji.css">
<title>太极图</title>
</head>
<body>
<div class="taiji"></div>
</body>
</html>
第二步,利用css样式构一个黑白半圆;
.taiji{
box-shadow: 0 0 30px #000000;
height: 400px;
border-left:200px solid #000000;
border-right:200px solid white;
border-radius:200px;
margin: 50px auto;
width: 0;
}
结果为:
第三步,用伪元素
.taiji:before{
content: "";
display: block;
width: 100px;
height: 100px;
background-color:white;
border-radius: 75px;
position: relative;
left: -48px;
top: 50px;
box-shadow: 0 0 0 50px black;
}
.taiji:after{
content: "";
display: block;
width: 100px;
height: 100px;
background-color: black;
border-radius: 75px;
position: relative;
left: -48px;
top: 150px;
box-shadow: 0 0 0 50px white;
}
结果,如图