gif

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!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>Spotlight on texts</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello World</h1>
</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
*{
/* Initialization, cancle the margin and padding of elements */
margin : 0;
padding: 0;

}

body{
background-color: #222;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

h1{
color: #333;
/* capitalize */
text-transform: uppercase;
font-size: 112px;
position: relative;
}
/* 伪元素 */
h1::after{
content: "hello world";
color: transparent;
position: absolute;
top: 0;
left: 0;
background: linear-gradient(to right, #ff59b3, #fe0000, #ffff01, #40d1d2, #8b059f7d);
/* change the background so that it fits exactly the text */
background-clip: text;
-webkit-background-clip: text;
/* clip the element so that it becomes a circle: 100 suggests the diameter, 0%, 50% suggests the position of the center of the circle */
clip-path: circle(100px at 0% 50%);
/* animation: name, duration, infinite means repeat */
animation: light 5s infinite;
}

/* define an animation that changes the position of the center of the circle */
@keyframes light{
0%{
clip-path: circle(100px at 0% 50%);
}
50%{
clip-path: circle(100px at 100% 50%);
}
100%{
clip-path: circle(100px at 0% 50%);
}
}