源码

边框动画

元素外框

1
<div class="border-box"></div>
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
body {
background: #000000;
}
.border-box {
width: 200px;
height: 200px;
box-shadow: 16px 14px 20px #000000;
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
justify-content: center;
align-items: center;
}
.border-box:before {
content: '';
width: 150%;
height: 150%;
position: absolute;
border-radius: 10px;
}
// 内部元素
.border-box:after {
content: 'Animation';
width: 190px;
height: 190px;
line-height: 190px;
text-align: center;
background: #000000;
color: red;
position: absolute;
border-radius: 10px;
letter-spacing: 5px;
box-shadow: inset 20px 20px 20px #000000;
}

添加外框颜色

1
2
3
4
.border-box:before {
/* ... */
background-image: conic-gradient(#ff0052 20deg, transparent 120deg);
}

外框旋转

边框动画

1
2
3
4
.border-box:before {
/* ... */
animation: rotate 2s linear infinite;
}

遮挡动画外框

1
2
3
4
.border-box {
/* ... */
overflow: hidden;
}

全部代码

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Border Animation</title>
<style>
body {
background: #000000;
}
.border-box {
width: 200px;
height: 200px;
box-shadow: 16px 14px 20px #000000;
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.border-box:before {
content: '';
background-image: conic-gradient(#ff0052 20deg, transparent 120deg);
width: 150%;
height: 150%;
position: absolute;
border-radius: 10px;
animation: rotate 2s linear infinite;
}
.border-box:after {
content: 'Animation';
width: 190px;
height: 190px;
line-height: 190px;
text-align: center;
background: #000000;
color: red;
position: absolute;
border-radius: 10px;
letter-spacing: 5px;
box-shadow: inset 20px 20px 20px #000000;
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(-360deg);
}
}
</style>
</head>
<body>
<div class="border-box"></div>
</body>
</html>

最后更新: 2022年04月18日 13:24