butterfly 主题的默认设计风格已经非常优雅,但如果需要个性化自定义就需要修改对应 CSS 配置,下列是我的博客正在使用的样式风格,其中自定义配置文件位于source/css/custom.css中。需通过butterfly配置文件的inject字段引入:

1
2
3
inject:
head:
- <link rel="stylesheet" href="/css/custom.css">

一、基础风格配置

1. 代码样式

1
2
3
4
5
6
7
8
9
code_blocks:
theme: pale night
macStyle: true
height_limit: 800
word_wrap: true
copy: true
language: true
shrink: false
fullpage: false

2. 页面顶图样式

1
2
3
4
5
6
7
8
9
10
11
12
disable_top_img: false
default_top_img: transparent
index_img: transparent
archive_img: false
tag_img: transparent
tag_per_img: transparent
category_img: transparent
category_per_img: transparent
footer_img: transparent
background: /img/core/bkgnd2.webp
index_site_info_top: 200px
index_top_img_height: 400px

二、自定义风格配置

1. 全局毛玻璃样式

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
/* 明亮模式 */
#body-wrap #recent-posts > .recent-post-item,
#body-wrap .recent-post-item,
#body-wrap #aside-content .card-widget,
#body-wrap .layout > div:first-child:not(.recent-posts),
#body-wrap #nav .menus_items .menus_item .menus_item_child,
#body-wrap #pagination .page-number:not(.current),
#body-wrap #pagination .extend,
#page-header #post-info {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(2px);
-webkit-backdrop-filter: blur(2px);
border: 1px solid rgba(255, 255, 255, 0.85);
box-shadow: 0 8px 16px -4px rgba(138, 138, 138, 0.15);
transition: background 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
}
#body-wrap #pagination .page-number:not(.current):hover,
#body-wrap #pagination .extend:hover {
background: #ff7142d2;
border-color: #ff7142d2;
color: #fff;
}
/* 夜间模式 */
html[data-theme="dark"] #body-wrap #recent-posts > .recent-post-item,
html[data-theme="dark"] #body-wrap .recent-post-item,
html[data-theme="dark"] #body-wrap #aside-content .card-widget,
html[data-theme="dark"] #body-wrap .layout > div:first-child:not(.recent-posts),
html[data-theme="dark"] #body-wrap #nav .menus_items .menus_item .menus_item_child,
html[data-theme="dark"] #body-wrap #pagination .page-number:not(.current),
html[data-theme="dark"] #body-wrap #pagination .extend,
html[data-theme="dark"] #page-header #post-info {
background: rgba(30, 30, 30, 0.6);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.2);
}

2. 明亮主题文本颜色

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
/* 主副标题 */
html:not([data-theme="dark"]) #site-title,
html:not([data-theme="dark"]) .site-title,
html:not([data-theme="dark"]) #site-name,
html:not([data-theme="dark"]) #site-info .site-subtitle,
html:not([data-theme="dark"]) #subtitle,
html:not([data-theme="dark"]) #nav #blog-info .site-name,
html:not([data-theme="dark"]) #nav #blog-info a {
color: #2c3e50 !important;
text-shadow: none !important;
}
/* 导航栏菜单、图标 */
html:not([data-theme="dark"]) #nav .site-page,
html:not([data-theme="dark"]) #nav .menus_items .menus_item > a > span,
html:not([data-theme="dark"]) #nav .menus_items .menus_item > a > i,
html:not([data-theme="dark"]) #search-button > a,
html:not([data-theme="dark"]) #search-button > a > span,
html:not([data-theme="dark"]) #search-button > a > i {
color: #2c3e50 !important;
text-shadow: none !important;
}
html:not([data-theme="dark"]) #nav .menus_item:hover > a,
html:not([data-theme="dark"]) #nav .menus_item:hover > a > span,
html:not([data-theme="dark"]) #nav .menus_item:hover > a > i {
color: #49b1f5 !important;
}
/* 底部与 Meta 数据 */
html:not([data-theme="dark"]) #page-header .page-title,
html:not([data-theme="dark"]) #footer,
html:not([data-theme="dark"]) #footer a,
html:not([data-theme="dark"]) #footer div,
html:not([data-theme="dark"]) #footer p,
html:not([data-theme="dark"]) #footer span,
html:not([data-theme="dark"]) #footer .copyright *,
html:not([data-theme="dark"]) #post-info .post-title,
html:not([data-theme="dark"]) #post-info #post-meta,
html:not([data-theme="dark"]) #post-info #post-meta a,
html:not([data-theme="dark"]) #post-info #post-meta .post-meta-separator,
html:not([data-theme="dark"]) #post-info #post-meta i {
color: #2c3e50 !important;
text-shadow: none !important;
}

3. 明亮主题导航栏子菜单颜色

1
2
3
4
5
6
7
8
9
10
html:not([data-theme="dark"]) #nav .menus_items .menus_item .menus_item_child li:hover,
html:not([data-theme="dark"]) #nav .menus_items .menus_item .menus_item_child li.active {
background: transparent !important;
}
html:not([data-theme="dark"]) #nav .menus_items .menus_item .menus_item_child li:hover a,
html:not([data-theme="dark"]) #nav .menus_items .menus_item .menus_item_child li:hover a span,
html:not([data-theme="dark"]) #nav .menus_items .menus_item .menus_item_child li.active a,
html:not([data-theme="dark"]) #post-info #post-meta a:hover {
color: #49b1f5 !important;
}

4. 页头与页脚透明

1
2
3
4
5
6
#footer, #page-header.post-bg, #page-header.page-bg {
background: transparent !important;
}
#page-header.post-bg::before, #page-header.page-bg::before {
background-color: transparent !important;
}

5. 文章卡片透明

1
2
3
4
5
6
7
8
9
10
#body-wrap #recent-posts > .recent-post-item .recent-post-info,
#body-wrap #recent-posts > .recent-post-item .recent-post-info::before,
#body-wrap #recent-posts > .recent-post-item .recent-post-info::after,
#body-wrap #recent-posts > .recent-post-item .recent-post-info > .article-title,
#body-wrap #recent-posts > .recent-post-item .recent-post-info > .article-meta-wrap,
#body-wrap #recent-posts > .recent-post-item .recent-post-info > .content {
background: transparent !important;
background-color: transparent !important;
box-shadow: none !important;
}

6. 文章标题卡片透明

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
/* 文章顶部卡片 */
#page-header #post-info {
position: absolute;
bottom: 0px;
left: 50%;
transform: translateX(-50%);
margin: 0;
padding: 20px 40px;
box-sizing: border-box;
display: block;
text-align: left;
border-radius: 10px;
}
@media screen and (max-width: 768px) {
#page-header #post-info {
padding: 15px 20px !important;
bottom: 20px !important;
}

#post-info #post-meta > .meta-firstline > span:not(.post-meta-wordcount),
#post-info #post-meta > .meta-secondline > span:not(.post-meta-wordcount) {
display: none !important;
}

#post-info #post-meta > .meta-firstline > .post-meta-separator,
#post-info #post-meta > .meta-secondline > .post-meta-separator {
display: none !important;
}

#post-info .post-title {
text-align: justify !important;
text-align-last: left !important;
display: block;
margin-bottom: 10px;
}
}

7. Mermaid 流程图透明

1
2
3
4
5
6
7
8
#article-container .mermaid,
#article-container .mermaid svg,
.mermaid-wrap,
#article-container .mermaid svg rect.mermaid-bg,
#article-container .mermaid svg rect:first-child {
background: transparent !important;
fill: transparent !important;
}

8. 明亮主题代码块配色

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
/* 全局颜色变量 */
html:not([data-theme="dark"]) {
--hl-bg: #f4f7fa !important;
--hltools-bg: #e9eef4 !important;
--hlnumber-bg: #f4f7fa !important;
--hlnumber-color: #8da4bb !important;
--hlscrollbar-bg: #dbe6f0 !important;
--hlexpand-bg: linear-gradient(180deg, rgba(244,247,250,0), rgba(244,247,250,0.9)) !important;
}
/* 代码块背景色 */
html:not([data-theme="dark"]) #article-container .highlight table {
background-color: #f4f7fa !important;
}
/* 关键字着色 */
html:not([data-theme="dark"]) .highlight .code .keyword,
html:not([data-theme="dark"]) .highlight .code .built_in,
html:not([data-theme="dark"]) .highlight .code .type {
color: #005cc5 !important;
}
/* 字符串着色 */
html:not([data-theme="dark"]) .highlight .code .string {
color: #22863a !important;
}
/* 注释着色 */
html:not([data-theme="dark"]) .highlight .code .comment {
color: #677886 !important;
font-style: italic !important;
}
/* 数字常量着色 */
html:not([data-theme="dark"]) .highlight .code .number {
color: #d130a5 !important;
}
/* 函数名与类标题着色 */
html:not([data-theme="dark"]) .highlight .code .title,
html:not([data-theme="dark"]) .highlight .code .function {
color: #0077aa !important;
}
/* 预处理指令与宏定义着色 */
html:not([data-theme="dark"]) .highlight .code .meta,
html:not([data-theme="dark"]) .highlight .code .meta-keyword {
color: #8b3c9b !important;
}
/* 局部变量与普通属性 */
html:not([data-theme="dark"]) .highlight .code .attr,
html:not([data-theme="dark"]) .highlight .code .variable,
html:not([data-theme="dark"]) .highlight .code .params {
color: #212f3b !important;
}

9. 夜间主题代码块配色

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
/* 全局颜色变量 */
html[data-theme="dark"] {
--hl-bg: #0b0f19 !important;
--hltools-bg: #111726 !important;
--hlnumber-bg: #0b0f19 !important;
--hlnumber-color: #5c6c7f !important;
--hlscrollbar-bg: #1e293b !important;
--hlexpand-bg: linear-gradient(180deg, rgba(11,15,25,0), rgba(11,15,25,0.9)) !important;
}
/* 代码块背景色 */
html[data-theme="dark"] #article-container .highlight table {
background-color: #0b0f19 !important;
}
/* 关键字着色 */
html[data-theme="dark"] .highlight .code .keyword,
html[data-theme="dark"] .highlight .code .built_in,
html[data-theme="dark"] .highlight .code .type {
color: #569cd6 !important;
}
/* 字符串着色 */
html[data-theme="dark"] .highlight .code .string {
color: #8fca5c !important;
}
/* 注释着色 */
html[data-theme="dark"] .highlight .code .comment {
color: #5c7080 !important;
font-style: italic !important;
}
/* 数字常量着色 */
html[data-theme="dark"] .highlight .code .number {
color: #f07178 !important;
}
/* 函数名与类标题着色 */
html[data-theme="dark"] .highlight .code .title,
html[data-theme="dark"] .highlight .code .function {
color: #82aaff !important;
}
/* 预处理指令与宏定义着色 */
html[data-theme="dark"] .highlight .code .meta,
html[data-theme="dark"] .highlight .code .meta-keyword {
color: #c792ea !important;
}
/* 局部变量与普通属性 */
html[data-theme="dark"] .highlight .code .attr,
html[data-theme="dark"] .highlight .code .variable,
html[data-theme="dark"] .highlight .code .params {
color: #a6bcdc !important;
}

10. 表格样式

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
/* 表头居中 */
#article-container table th,
#article-container table thead th {
text-align: center !important;
}

/* ================== 明亮模式 ================== */
/* 表格半透明 */
html:not([data-theme="dark"]) #article-container table {
background-color: rgba(255, 255, 255, 0.5) !important;
}
/* 边框线条颜色 */
html:not([data-theme="dark"]) #article-container table,
html:not([data-theme="dark"]) #article-container table th,
html:not([data-theme="dark"]) #article-container table td {
border-color: #919191da !important;
border-width: 1px !important;
}
/* 偶数行颜色 */
html:not([data-theme="dark"]) #article-container table tbody tr:nth-child(even) {
background-color: rgba(240, 244, 248, 0.5) !important;
}

/* ================== 夜间模式 ================== */
/* 表格半透明 */
html[data-theme="dark"] #article-container table {
background-color: rgba(22, 27, 34, 0.5) !important;
}
/* 边框线条颜色 */
html[data-theme="dark"] #article-container table,
html[data-theme="dark"] #article-container table th,
html[data-theme="dark"] #article-container table td {
border-color: #5c6c7f !important;
border-width: 1px !important;
}
/* 偶数行颜色 */
html[data-theme="dark"] #article-container table tbody tr:nth-child(even) {
background-color: rgba(30, 36, 44, 0.5) !important;
}

11. 排版美化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

/* 无顶图页面正文标题居中 */
#body-wrap #page .page-title {
text-align: center !important;
}

/* 文章排版改为两端对齐 */
#article-container {
text-align: justify;
}

/* 视频自适应页面尺寸 */
iframe[src*="youtube.com"],
iframe[src*="youtu.be"],
iframe[src*="vimeo.com"] {
display: block;
max-width: 100%;
width: 100%;
aspect-ratio: 16 / 9;
height: auto;
}

12. pangu 插件引入

  由于新版本butterfly已不再内置pangu插件,因此需要通过inject字段引入:

1
2
3
4
inject:
bottom:
- <script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.7/pangu.min.js"></script>
- <script> const initPangu = () => { if (typeof pangu !== 'undefined') { pangu.spacingPage(); } }; document.addEventListener('DOMContentLoaded', initPangu); document.addEventListener('pjax:complete', initPangu); </script>

13. 页脚信息插入

  在页脚中添加版权信息备案号等内容,添加网站运行时间脚本接口:

1
2
3
4
5
6
7
8
9
10
footer:
nav:
owner:
enable: true
since: 2023
# Copyright of theme and framework
copyright:
enable: false
version: true
custom_text: <dev><a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">陕ICP备2025072980号-1</a></dev><div id="workboard"></div>

  为了美观展示建站以来的网站运行时间,建议从互联网下载电子钟字体UnidreamLED.ttf,将字体文件放置在source/font/目录下,并在source/css/runtime.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
/* 电子钟字体引入 */
@font-face {
font-family: 'UnidreamLED';
src: url('../font/UnidreamLED.ttf');
font-display: swap;
}

div#runtime {
width: fit-content;
max-width: 100%;
margin: 0px auto;
color: #333333;
padding: 0px 0px;
border-radius: 10px;
background-color: transparent;
font-family: 'UnidreamLED', 'PingFang SC', 'Microsoft YaHei', sans-serif;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 5px;
}

html[data-theme="dark"] div#runtime {
color: #c0c0c0;
}

  在source/js/runtime.js中添加以下脚本:

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
function updateRuntime() {
const createTime = new Date('2023-01-12T00:00:00').getTime();
const now = new Date().getTime();
let totalSeconds = Math.floor((now - createTime) / 1000);
const daysInYear = 365;
const years = Math.floor(totalSeconds / (daysInYear * 24 * 3600));
totalSeconds %= (daysInYear * 24 * 3600);

const days = Math.floor(totalSeconds / (24 * 3600));
totalSeconds %= (24 * 3600);

const hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;

const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;

const formatZero = (num) => num > 9 ? num : '0' + num;

const currentHour = new Date().getHours();
let statusHtml = "";

if (currentHour >= 8 && currentHour < 22) {
statusHtml = "<span class='boardsign-text'>🌞 小窝营业中 — </span>";
} else {
statusHtml = "<span class='boardsign-text'>🌙 小窝打烊了 — </span>";
}

const timeHtml = `已度过 ${years}${days}${formatZero(hours)} : ${formatZero(minutes)} : ${formatZero(seconds)}`;
const currentTimeHtml = `<div id='runtime'>${statusHtml}${timeHtml}</div>`;

const workboard = document.getElementById("workboard");
if (workboard) {
workboard.innerHTML = currentTimeHtml;
}
}

updateRuntime();
setInterval(updateRuntime, 1000);