前言
不久前有一次面试,面试官考察我基本功和开放性思维,当时说了思路。今天得空,实现了一把。最终成品如图:
分析
将目标拆解为 7 个 div,使用绝对定位思路:
- 【width = 400; height = 400; border = 1】 大圆
- 【radius = 200】 左半圆 border实现
- 【radius = 200】 右半圆 border实现
- 【radius = 100】 上半圆 border实现
- 【radius = 100】 下半圆 border实现
- 【radius = 25】 上小圆
- 【radius = 25】 下小圆
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>太极</title>
<style>
#root {
width: 400px;
height: 400px;
background-color: #eee;
margin: 100px auto;
border: 1px solid #000;
border-radius: 201px;
position: relative;
}
#leftArc {
border-width: 200px 0 200px 200px;
border-style: solid;
border-radius: 200px 0 0 200px;
border-color: #000;
position: absolute;
}
#rightArc {
border-width: 200px 200px 200px 0;
border-style: solid;
border-radius: 0 200px 200px 0;
border-color: #fff;
position: absolute;
left: 200px;
}
#leftMediumArc {
border-width: 100px 0 100px 100px;
border-style: solid;
border-radius: 100px 0 0 100px;
border-color: #fff;
position: absolute;
left: 25%;
}
#rightMediumArc {
border-width: 100px 100px 100px 0;
border-style: solid;
border-radius: 0 100px 100px 0;
border-color: #000;
position: absolute;
left: 50%;
top: 200px;
}
#miniBlackCircle {
border: 25px solid #000;
border-radius: 50%;
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
}
#miniWhiteCircle {
border: 25px solid #fff;
border-radius: 50%;
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div id="root">
<div id="leftArc"></div>
<div id="rightArc"></div>
<div id="leftMediumArc">
<div id="miniBlackCircle"></div>
</div>
<div id="rightMediumArc">
<div id="miniWhiteCircle"></div>
</div>
</div>
</div>
</body>
</html>
(完)
网友评论