文章重要更新 240803

  • 简化教程,直接贴源码
  • 适配任何博客背景,对背景色无要求。文章圆满。
本文不涉及对主题源代码的修改

本文已收录至 Butterfly 主题美化教程

CodePen 是个好东西,利用好里面现成的项目,我们可以尝试更换 Butterfly 主题的页脚。

在官方文档中 Butterfly 安裝文檔(三) 主題配置-1 | Butterfly(阅读本文务必先阅读这一部分),给出了自定义页脚的修改方式,但这种方法只适合写写版权信息、备案号这些,不适合高级定制。

接下来我将介绍利用 CodePen 项目定制页脚的方法。

效果展示

原项目预览:

image.png

移植到本博客后预览:

image.png

基本思路

本小节讲思路哈,先别着急实践。

原项目中 footer 内的内容是展示的最主要的 HTML 内容,应该填入主题配置文件 custom_text 字段(详看 Butterfly 安裝文檔(三) 主題配置-1 | Butterfly

image.png

接着挑选项目样式内容,复制到新建的 CSS 文件中并将其引入到我们的主题中。Butterfly 主题引入外部 CSS 的方法为在主题配置文件 _config.butterfly.yml 的 inject 部分引入 CSS,例如:

1
2
3
4
5
inject:
head:
- <link rel="stylesheet" href="your css"> # 在这里引入
bottom:
- <script src="your js"></script>

下文附我的完整 CSS 文件,和注入的内容。

CSS 样式文件

本节之后的内容就是具体的实操部分。

请将下面的 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

#footer-wrap {
font-family: 'Roboto', sans-serif;
padding: 0;
}


#footer {
background-color: rgba(0,0,0,0); /* 修改透明色 */
color: #fff;
padding: 0;
}

.footer-logo {
color: white;
}

.footer-wave-svg {
height: 50px;
width: 100%;
transform: scale(-1, -1) translateY(-10px); /*;*/
}

.footer-wave-path {
fill: #177ecd;
}

.footer-content {
margin-left: auto;
margin-right: auto;
max-width: 1230px;
padding: 40px 15px 450px;
position: relative;
}

.footer-content-column {
box-sizing: border-box;
float: left;
padding-left: 15px;
padding-right: 15px;
width: 100%;
color: #fff;
}

.footer-content-column ul li a {
color: #fff;
text-decoration: none;
}

.footer-logo-link {
display: inline-block;
}

.footer-menu {
margin-top: 15px;
}

.footer-menu-name {
color: #fffff2;
font-size: 15px;
font-weight: 900;
letter-spacing: .1em;
line-height: 18px;
margin-bottom: 0;
margin-top: 0;
text-transform: uppercase;
}

.footer-menu-list {
list-style: none;
margin-bottom: 0;
margin-top: 10px;
padding-left: 0;
}

.footer-menu-list li {
margin-top: 5px;
}

.footer-call-to-action-description {
color: #fffff2;
margin-top: 10px;
margin-bottom: 20px;
}

.footer-call-to-action-button:hover {
background-color: #fffff2;
color: #00bef0;
}

.button:last-of-type {
margin-right: 0;
}

.footer-call-to-action-button {
background-color: #027b9a;
border-radius: 21px;
color: #fffff2;
display: inline-block;
font-size: 11px;
font-weight: 900;
letter-spacing: .1em;
line-height: 18px;
padding: 12px 30px;
margin: 0 10px 10px 0;
text-decoration: none;
text-transform: uppercase;
transition: background-color .2s;
cursor: pointer;
position: relative;
}

.footer-call-to-action {
margin-top: 17px;
}

.footer-call-to-action-title {
color: #fffff2;
font-size: 14px;
font-weight: 900;
letter-spacing: .1em;
line-height: 18px;
margin-bottom: 0;
margin-top: 0;
text-transform: uppercase;
}

.footer-call-to-action-link-wrapper {
margin-bottom: 0;
margin-top: 10px;
color: #fff;
text-decoration: none;
}

.footer-call-to-action-link-wrapper a {
color: #fff;
text-decoration: none;
}


.footer-social-links {
bottom: -1px;
height: 54px;
position: absolute;
right: 0;
width: 236px;
}

.footer-social-amoeba-svg {
height: 54px;
left: 0;
display: block;
position: absolute;
top: 0;
width: 236px;
}

.footer-social-amoeba-path {
fill: #027b9a;
}

.footer-social-link.email {
height: 41px;
left: 4px;
top: 14px;
width: 41px;
}

.footer-social-link {
display: block;
padding: 10px;
position: absolute;
}

.hidden-link-text {
position: absolute;
clip: rect(1px 1px 1px 1px);
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(0px 0px 99.9% 99.9%);
clip-path: inset(0px 0px 99.9% 99.9%);
overflow: hidden;
height: 1px;
width: 1px;
padding: 0;
border: 0;
top: 50%;
}

.footer-social-icon-svg {
display: block;
}

.footer-social-icon-path {
fill: #fffff2;
transition: fill .2s;
}

.footer-social-link.fish {
height: 47px;
left: 121px;
top: 13px;
width: 47px;
}

.footer-social-link.rss {
height: 43px;
left: 178px;
top: 10px;
width: 43px;
}

.footer-social-link.github {
height: 62px;
left: 54px;
top: -4px;
width: 62px;
}

.footer-copyright {
background-color: #027b9a;
color: #fff;
padding: 15px 30px;
text-align: center;
}

.footer-copyright-wrapper {
margin-left: auto;
margin-right: auto;
max-width: 1200px;
}

.footer-copyright-text {
color: #fff;
font-size: 13px;
font-weight: 400;
line-height: 18px;
margin-bottom: 0;
margin-top: 0;
}

.footer-copyright-link {
color: #fff;
text-decoration: none;
}

.footer-content-div{
background: #177ecd
}

.footer-svg-div{
width: 100%;
max-height: 200px;
}

/* Media Query For different screens */
@media (min-width: 320px) and (max-width: 479px) {
/* smartphones, portrait iPhone, portrait 480x320 phones (Android) */
.footer-content {
margin-left: auto;
margin-right: auto;
max-width: 1230px;
padding: 40px 15px 649px;
position: relative;
}

/* 不展示logo */
.footer-logo{
display: none;
}
}

@media (min-width: 480px) and (max-width: 599px) {
/* smartphones, Android phones, landscape iPhone */
.footer-content {
margin-left: auto;
margin-right: auto;
max-width: 1230px;
padding: 40px 15px 738px;
position: relative;
}

.footer-logo{
padding-left: 177px; /* Qlogo 稍微偏移一点 */
padding-right: 170px;
}
}

@media (min-width: 600px) and (max-width: 800px) {
/* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */
.footer-content {
margin-left: auto;
margin-right: auto;
max-width: 1230px;
padding: 40px 15px 758px;
position: relative;
}
}

@media (min-width: 801px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */

}

@media (min-width: 1025px) {
/* big landscape tablets, laptops, and desktops */

}

@media (min-width: 1281px) {
/* hi-res laptops and desktops */

}


@media (min-width: 760px) {
.footer-content {
margin-left: auto;
margin-right: auto;
max-width: 1230px;
padding: 10px 15px 237px;
position: relative;
}

.footer-content-column {
/*五列的话 19.99 %*/
width: 24.99%;
}
}

@media (min-width: 568px) {

}

@media (min-width: 600px) and (max-width: 760px) {
/* 在这里编写适用于小屏幕的样式 */
.footer-logo{
padding-left: 212px; /* Qlogo 稍微偏移一点 */
padding-right: 204px;
}
}

在这个文件中,我对原项目的改进点:

  • 解决边框问题
  • 不同宽度屏幕的适应
  • 改进波浪效果,使其在不同博客背景中均能得到很好的展现。

夜间模式

Butterfly 主题有夜间模式,为了实现更好的波浪效果,建议增加以下 CSS 字段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* 页脚波浪的颜色 */
[data-theme='dark'] .footer-wave-path {
fill: #0f3858;
}
[data-theme='dark'] .footer-content-div {
background-color: #0f3858;
}

/* 页脚海底的颜色 */
[data-theme='dark'] .footer-copyright {
background-color: #104e5e;
}
[data-theme='dark'] .footer-social-amoeba-path {
fill: #104e5e;
}

预览:

image.png

关于夜间模式的问题详见:站内文章Butterfly 夜间模式变换顶部网站图标

注入 HTML

打开主题配置文件 _config.butterfly.yml,写入以下内容(以目前我的页脚为例,具体内容请自行修改):

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
# Footer Settings
# --------------------------------------
footer:
owner:
enable: false
since: 2022
custom_text: |
<div class="footer-svg-div">
<svg class="footer-wave-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 100" preserveAspectRatio="none">
<path class="footer-wave-path" d="M851.8,100c125,0,288.3-45,348.2-64V0H0v44c3.7-1,7.3-1.9,11-2.9C80.7,22,151.7,10.8,223.5,6.3C276.7,2.9,330,4,383,9.8 c52.2,5.7,103.3,16.2,153.4,32.8C623.9,71.3,726.8,100,851.8,100z"></path>
</svg>
</div>
<div class="footer-content-div" >
<div class="footer-content">
<div class="footer-content-column">
<div class="footer-logo">
<a class="footer-logo-link" href="#">
<span class="hidden-link-text">LOGO</span>
<img src="https://cdn.gallery.uuanqin.top/img/A%E5%85%A8%E7%99%BD%E6%97%A0%E5%AD%97.png" style="height:40%; width:40%">
</a>
</div>
<div class="footer-menu">
<h2 class="footer-menu-name">开始</h2>
<ul id="menu-get-started" class="footer-menu-list">
<li class="menu-item menu-item-type-post_type menu-item-object-product">
<a href="/sitemap.xml">站点地图</a>
</li>
</ul>
</div>
</div>
<div class="footer-content-column">
<div class="footer-menu">
<h2 class="footer-menu-name">快速链接</h2>
<ul id="menu-company" class="footer-menu-list">
<li class="menu-item menu-item-type-taxonomy menu-item-object-category">
<a href="/archives/">时间轴</a>&nbsp;|&nbsp;<a href="/DO_NOT_render/cosmoscope/cosmoscope_trim.html">关系图</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-product">
框架&nbsp;<a href="https://hexo.io/zh-cn/">Hexo</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-product">
主题&nbsp;<a href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-product">
<a href="https://www.foreverblog.cn/" rel="noopener external nofollow noreferrer" target="_blank" > <img class="img-foreverblog" src="https://cdn.gallery.uuanqin.top/img/forever_logo_en_default_white.png" alt="" style="width:auto;height:21px;margin-top:6px"> </a>
</li>
</ul>
</div>

</div>

<div class="footer-content-column">
<div class="footer-menu">
<h2 class="footer-menu-name">法律声明</h2>
<ul id="menu-legal" class="footer-menu-list">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-privacy-policy menu-item-170434">
<a href="/pages/privacy.html">隐私政策</a>
</li>
</ul>
</div>
<div class="footer-call-to-action">
<h2 class="footer-call-to-action-title">联系本站</h2>
<ul id="menu-legal" class="footer-menu-list">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-privacy-policy menu-item-170434">
<a href="/DO_NOT_render/wechatOA/index.html">微信公众号</a>
</li>

<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-privacy-policy menu-item-170434">
<a class="footer-call-to-action-link" href="mailto:[email protected]" target="_self">
uuan<span style="display:none">@</span>qi<!-- >@ -->n@<span style="display:none">@</span>uu<!-- >@. -->an<span style="display:none">@</span>qin.top
</a>
</li>

</ul>
</div>

</div>
<div class="footer-content-column">
<ul id="menu-get-started" class="footer-menu-list">
<li class="menu-item menu-item-type-post_type menu-item-object-product">
<a href="/pages/ai_policy.html" ><img class="img-not-ai" src="https://cdn.gallery.uuanqin.top/img/Written-By-Human-Not-By-AI-Badge-white.svg" alt="Written by Human, Not by AI"></a>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-product">
<a href="/pages/cc.html" ><img src="https://cdn.gallery.uuanqin.top/img/by-nc-sa.svg" alt="署名-非商业性使用-相同方式共享 4.0 国际"></a>
</li>

<li class="menu-item menu-item-type-post_type menu-item-object-product">
©2022-2024 By wuanqin
</li>
</ul>
</div>

<div class="footer-social-links"> <svg class="footer-social-amoeba-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 236 54">
<path class="footer-social-amoeba-path" d="M223.06,43.32c-.77-7.2,1.87-28.47-20-32.53C187.78,8,180.41,18,178.32,20.7s-5.63,10.1-4.07,16.7-.13,15.23-4.06,15.91-8.75-2.9-6.89-7S167.41,36,167.15,33a18.93,18.93,0,0,0-2.64-8.53c-3.44-5.5-8-11.19-19.12-11.19a21.64,21.64,0,0,0-18.31,9.18c-2.08,2.7-5.66,9.6-4.07,16.69s.64,14.32-6.11,13.9S108.35,46.5,112,36.54s-1.89-21.24-4-23.94S96.34,0,85.23,0,57.46,8.84,56.49,24.56s6.92,20.79,7,24.59c.07,2.75-6.43,4.16-12.92,2.38s-4-10.75-3.46-12.38c1.85-6.6-2-14-4.08-16.69a21.62,21.62,0,0,0-18.3-9.18C13.62,13.28,9.06,19,5.62,24.47A18.81,18.81,0,0,0,3,33a21.85,21.85,0,0,0,1.58,9.08,16.58,16.58,0,0,1,1.06,5A6.75,6.75,0,0,1,0,54H236C235.47,54,223.83,50.52,223.06,43.32Z"></path>
</svg>
<a class="footer-social-link github" href="https://github.com/uuanqin" target="_blank">
<span class="hidden-link-text">Github</span>
<svg class="footer-social-icon-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<path class="footer-social-icon-path" d="M 16 4 C 9.371094 4 4 9.371094 4 16 C 4 21.300781 7.4375 25.800781 12.207031 27.386719 C 12.808594 27.496094 13.027344 27.128906 13.027344 26.808594 C 13.027344 26.523438 13.015625 25.769531 13.011719 24.769531 C 9.671875 25.492188 8.96875 23.160156 8.96875 23.160156 C 8.421875 21.773438 7.636719 21.402344 7.636719 21.402344 C 6.546875 20.660156 7.71875 20.675781 7.71875 20.675781 C 8.921875 20.761719 9.554688 21.910156 9.554688 21.910156 C 10.625 23.746094 12.363281 23.214844 13.046875 22.910156 C 13.15625 22.132813 13.46875 21.605469 13.808594 21.304688 C 11.144531 21.003906 8.34375 19.972656 8.34375 15.375 C 8.34375 14.0625 8.8125 12.992188 9.578125 12.152344 C 9.457031 11.851563 9.042969 10.628906 9.695313 8.976563 C 9.695313 8.976563 10.703125 8.65625 12.996094 10.207031 C 13.953125 9.941406 14.980469 9.808594 16 9.804688 C 17.019531 9.808594 18.046875 9.941406 19.003906 10.207031 C 21.296875 8.65625 22.300781 8.976563 22.300781 8.976563 C 22.957031 10.628906 22.546875 11.851563 22.421875 12.152344 C 23.191406 12.992188 23.652344 14.0625 23.652344 15.375 C 23.652344 19.984375 20.847656 20.996094 18.175781 21.296875 C 18.605469 21.664063 18.988281 22.398438 18.988281 23.515625 C 18.988281 25.121094 18.976563 26.414063 18.976563 26.808594 C 18.976563 27.128906 19.191406 27.503906 19.800781 27.386719 C 24.566406 25.796875 28 21.300781 28 16 C 28 9.371094 22.628906 4 16 4 Z "></path>
</svg>
</a>
<a class="footer-social-link email" href="mailto:[email protected]" target="_blank">
<span class="hidden-link-text">Email</span>
<svg class="footer-social-icon-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path class="footer-social-icon-path" d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z"/>
</svg>
</a>
<a class="footer-social-link fish" href="https://uuanqin.top/404.html" target="_blank">
<span class="hidden-link-text">爱发电</span>
<svg class="footer-social-icon-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
<!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path class="footer-social-icon-path" d="M180.5 141.5C219.7 108.5 272.6 80 336 80s116.3 28.5 155.5 61.5c39.1 33 66.9 72.4 81 99.8c4.7 9.2 4.7 20.1 0 29.3c-14.1 27.4-41.9 66.8-81 99.8C452.3 403.5 399.4 432 336 432s-116.3-28.5-155.5-61.5c-16.2-13.7-30.5-28.5-42.7-43.1L48.1 379.6c-12.5 7.3-28.4 5.3-38.7-4.9S-3 348.7 4.2 336.1L50 256 4.2 175.9c-7.2-12.6-5-28.4 5.3-38.6s26.1-12.2 38.7-4.9l89.7 52.3c12.2-14.6 26.5-29.4 42.7-43.1zM448 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"/>
</svg>
</a>
<a class="footer-social-link rss" href="/atom.xml" target="_blank">
<span class="hidden-link-text">RSS</span>
<svg class="footer-social-icon-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path class="footer-social-icon-path" d="M0 64C0 46.3 14.3 32 32 32c229.8 0 416 186.2 416 416c0 17.7-14.3 32-32 32s-32-14.3-32-32C384 253.6 226.4 96 32 96C14.3 96 0 81.7 0 64zM0 416a64 64 0 1 1 128 0A64 64 0 1 1 0 416zM32 160c159.1 0 288 128.9 288 288c0 17.7-14.3 32-32 32s-32-14.3-32-32c0-123.7-100.3-224-224-224c-17.7 0-32-14.3-32-32s14.3-32 32-32z"/>
</svg>
</a>

</div>
</div>
</div>
<div class="footer-copyright">
<div class="footer-copyright-wrapper">
<p class="footer-copyright-text">
<a href="https://beian.miit.gov.cn/" rel="noopener external nofollow noreferrer"><img class="icp-icon" src="https://cdn.gallery.uuanqin.top/img/icp.ico"><span>津ICP备2022002156号-1</span></a>
&nbsp;|&nbsp;<a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12011202000621" rel="noopener external nofollow noreferrer"><img class="icp-icon" src="https://cdn.gallery.uuanqin.top/img/备案图标.png"><span>津公网安备 12011202000621号</span></a>
&nbsp;|&nbsp;&nbsp;
<span>互联网违法和不良信息举报邮箱:
uuan<span style="display:none">@</span>qi<!-- >@ -->n@<span style="display:none">@</span>uu<!-- >@. -->an<span style="display:none">@</span>qin.top
</span>
</p>
</div>
</div>

现在,你就能得到本站一模一样的样式,接下来按需更改就行。

更换社交图标

对应着项目 HTML 代码自己替换 SVG 代码更改社交图标。如果你是在 font awesome 复制过来的话,注意几个地方:

image.png

反正跟原来的对上就行。

后记

一年后花了大半天解决波浪效果背景色问题,TMD 又是 CSS,吐槽吐槽吐槽!以后绝不碰前端!

感谢讯飞星火的支持,简化了样式调整开发工作!

已知问题

  • 目前仅适用于博客背景为默认色(白天白,夜晚黑)的情况。240803 解决。
  • 移动端 Edge 打开浏览器的夜间模式,并勾选「所有网页均为深色主题」选项时,页脚波浪顶部有白条。但这是 Edge 的问题,该设置温馨提示「打开后某些网站会不美观」的提示。230816 240715