HTML+CSS: Blinking Rhombus

blinking_rhombus

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!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>菱形加载动画</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="loading">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</body>
</html>

style.css

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
body{
margin: 0;
padding: 0;
height: 100vh;
/*place the content at the center, set body as flex container, thus the div element is the flex item*/
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(200deg,#f4efef,#e3eeff);
}

.loading{
width: 200px;
height: 200px;
/* grid display */
display: grid;
/* set the grid to be three columns per row */
grid-template-columns: repeat(3,1fr);
/* set the gap between grid items: both horizontally and vertically gap */
gap: 10px;
/* number the items for later use: nth-child() */
/* counter-reset: number; */
/* ctrl + shift / */
/* rotate by 45 degrees */
transform: rotate(45deg);
}

.loading span{
/* user-defined property: grammar is `--` followed by name */
--c:red;
background-color: var(--c);
position: relative;
transform: rotate(0);
/* animation name duration easing function repeat */
animation: blinking 2s linear infinite;
/* wait for a few sec */
animation-delay: var(--d);
}

.loading span::before{
/* setting increasing number */
/* counter-increment: number; */
/* */
/* content:counter(number); */
color: #fff;
position: absolute;
width: 100%;
height: 100%;
}

.loading span:nth-child(7){
--c:#f15a5a;
--d:0s;
}

.loading span:nth-child(4),
.loading span:nth-child(8){
--c:#f0c419;
--d:0.2s;
}

.loading span:nth-child(1),
.loading span:nth-child(5),
.loading span:nth-child(9){
--c:#4eba6f;
--d:0.4s;
}

.loading span:nth-child(2),
.loading span:nth-child(6){
--c:#2d95bf;
--d:0.6s;
}

.loading span:nth-child(3){
--c:#955ba5;
--d:0.8s;
}

@keyframes blinking {
0%,100%{
/* scale(x,y) suggests the change in width and height*/
transform: scale(0);
}
40%,80%{
transform: scale(1);
}
}