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; }
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: 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);
|