-
Notifications
You must be signed in to change notification settings - Fork 16
/
10-纯 CSS 创作闪闪发光的霓虹灯文字.html
89 lines (80 loc) · 2.52 KB
/
10-纯 CSS 创作闪闪发光的霓虹灯文字.html
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
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>纯 CSS 创作闪闪发光的霓虹灯文字</title>
<!--参考文章 https://segmentfault.com/a/1190000015939758 -->
<style>
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.neon {
position: relative;
overflow: hidden;
/* 调高亮度 */
filter: brightness(200%);
}
.text {
background-color: black;
color: white;
font-size: 80px;
font-weight: bold;
font-family: sans-serif;
text-transform: uppercase;
/* 文字不能被选中 */
user-select: none;
}
.text::before {
/* 用伪元素和数据属性增加文字,产生描边效果 */
content: attr(data-text);
position: absolute;
color: white;
filter: blur(0.02em);
/* 用混色模式产生描边效果 */
mix-blend-mode: difference;
}
.gradient {
position: absolute;
/* 设置渐变色背景 */
background: linear-gradient(45deg, red, gold, lightgreen, gold, red);
top: 0;
left: 0;
right: 0;
bottom: 0;
/* 设置渐变色背景 */
mix-blend-mode: multiply;
}
.spotlight {
position: absolute;
top: -100%;
left: -100%;
right: 0;
bottom: 0;
/* 用径向渐变制作光影背景 */
background: radial-gradient( circle, white, transparent 25%) center / 25% 25%, radial-gradient( circle, white, black 25%) center / 12.5% 12.5%;
animation: light 5s linear infinite;
mix-blend-mode: color-dodge;
}
/* 设置光影移动的动画效果 */
@keyframes light {
to {
transform: translate(50%, 50%);
}
}
</style>
</head>
<body>
<div class="neon">
<span class="text" data-text="thanks">thanks</span>
<span class="gradient"></span>
<span class="spotlight"></span>
</div>
</body>
</html>