CSS实现github右上角图标
# 实现效果
# 代码如下
封装的组件如下
<script setup>
const githubLink = "https://github.com/Jinuss/maps";
</script>
<template>
<a :href="githubLink" class="icss-github-corner"><i></i></a>
</template>
<style scoped>
/* github corner */
a.icss-github-corner,
a.icss-github-corner-left {
font-size: 2.5em;
position: fixed;
top: 0;
right: 0;
z-index: 1000;
color: #fff;
background-color: #333;
padding: 0.5em 1.8em 0;
text-align: center;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 3.9em 3em;
-ms-transform-origin: 3.9em 3em;
transform-origin: 3.9em 3em;
overflow: hidden;
}
a.icss-github-corner-left {
left: 0;
right: auto;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 1em 3.1em;
-ms-transform-origin: 1em 3.1em;
transform-origin: 1em 3.1em;
}
a.icss-github-corner:hover i,
a.icss-github-corner-left:hover i {
-webkit-animation: vertical 2s ease;
animation: vertical 2s ease;
}
a.icss-github-corner i,
a.icss-github-corner-left i,
i.icss-github-corner {
color: #fff;
position: relative;
display: inline-block;
font-style: normal;
background-color: currentColor;
-webkit-box-sizing: border-box;
box-sizing: border-box;
vertical-align: middle;
width: 0.8em;
height: 0.6em;
-webkit-border-radius: 45% 45% 45% 45% / 50%;
border-radius: 45% 45% 45% 45% / 50%;
background-color: currentColor;
-webkit-box-shadow: 0 0.35em 0 -0.2em, 0 0.38em 0 -0.2em, 0 0.41em 0 -0.2em, 0
0.44em 0 -0.2em, 0 0.47em 0 -0.2em;
box-shadow: 0 0.35em 0 -0.2em, 0 0.38em 0 -0.2em, 0 0.41em 0 -0.2em, 0 0.44em
0 -0.2em, 0 0.47em 0 -0.2em;
margin: 0.12em 0.1em 0.23em;
}
a.icss-github-corner i:before,
a.icss-github-corner-left i:before,
i.icss-github-corner:before {
content: "";
border-width: 0;
position: absolute;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-width: 0.15em 0.15em;
border-style: solid;
-webkit-border-radius: 0.02em 60% 100% 80%;
border-radius: 0.02em 60% 100% 80%;
left: 0;
top: -0.07em;
-webkit-transform: rotate(20deg);
-ms-transform: rotate(20deg);
transform: rotate(20deg);
}
a.icss-github-corner i:after,
a.icss-github-corner-left i:after,
i.icss-github-corner:after {
content: "";
border-width: 0;
position: absolute;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-width: 0.15em 0.15em;
border-style: solid;
-webkit-border-radius: 0.02em 80% 100% 60%;
border-radius: 0.02em 80% 100% 60%;
left: 0.5em;
top: -0.07em;
-webkit-transform: rotate(65deg);
-ms-transform: rotate(65deg);
transform: rotate(65deg);
}
@-webkit-keyframes vertical {
0% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
4% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
8% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
12% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
16% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
20% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
22%,
100% {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
}
@keyframes vertical {
0% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
4% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
8% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
12% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
16% {
-webkit-transform: translate(0, -3px);
transform: translate(0, -3px);
}
20% {
-webkit-transform: translate(0, 3px);
transform: translate(0, 3px);
}
22%,
100% {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
}
</style>
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
编辑 (opens new window)
上次更新: 2024/08/13, 03:05:08