# 你知道原生 CSS 如何实现雷达图吗?
<style>
/* TODO雷达图 */
.radar {
margin: 400px;
/* 超出大圆部分隐藏 */
overflow: hidden;
position: relative;
width: 200px;
height: 200px;
box-sizing: border-box;
border-radius: 50%;
border: 1px solid aquamarine;
}
/* 利用伪元素的边框画中间相互垂直的两条线 */
/* 伪元素默认是行盒:记得变成块盒 */
/* 伪元素默认没有内容不显示:记得设置content */
.radar::after {
display: block;
content: '';
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 200px;
border-right: 1px solid aquamarine;
}
.radar::before {
display: block;
content: '';
width: 200px;
height: 100px;
border-bottom: 1px solid aquamarine;
}
/* 设置中间的小圆 */
.fan {
width: 100px;
height: 100px;
border: 1px solid aquamarine;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
.fan::before {
display: block;
content: '';
width: 100px;
height: 100px;
/* 往下倾斜10度 */
transform: skew(-10deg);
/* 用渐变色设置背景图 */
background-image: linear-gradient(to right, transparent, aquamarine);
/* 将元素移动到右上角 */
position: absolute;
top: -50%;
right: -50%;
/* 设置动画旋转点:左下角 */
transform-origin: 0 100%;
/* 动画函数名称 */
animation: rotateRadar 2s linear infinite;
}
@keyframes rotateRadar {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
</style>
<body>
<div class="radar">
<div class="fan"></div>
</div>
</body>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
效果如下: