自定义样式魔改
Butterfly主题魔改教程,自定义样式魔改。
1.自定义样式魔改引入
引入魔改样式的方法很简单,自建一个 css 文件,然后引入即可。
以 butterfly
主题为例:可以在 [Blogroot]\themes\butterfly\source\css\
目录下新建 custom.css
文件,然后在 [Blogroot]\_config.butterfly.yml
的 inject
配置项中引入自定义样式文件。
inject: head: - <link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'">
|
其中 media="defer" onload="this.media='all'"
是异步加载配置项,确保自定义样式会在页面加载完成后才继续渲染。如果没有需求或效果不好可以不加这个
。
2.站点动态 title
站点动态 title
是通过 js 监测是否聚焦于当前页面,从而替换标签显示内容。
在 [Blogroot]\themes\butterfly\source\js\
目录下新建 diytitle.js
:
var OriginTitile = document.title; var titleTime; document.addEventListener('visibilitychange', function () { if (document.hidden) { document.title = 'w(゚Д゚)w 不要走!再看看嘛!'; clearTimeout(titleTime); } else { document.title = '♪(^∇^*)欢迎回来!' + OriginTitile; titleTime = setTimeout(function () { document.title = OriginTitile; }, 2000); } });
|
在 [Blogroot]\_config.butterfly.yml
的 inject
配置项添加引入,此处因为这是个独立的 js,而且体量极小,所以可以添加 async
异步加载标签:
inject: head: # - <link rel="stylesheet" href="/xxx.css"> bottom: # - <script src="xxxx"></script> + - <script async src="/js/diytitle.js"></script>
|
3.夜间模式或阅读模式修改
Butterfly
主题使用 [data-theme='dark']
来界定夜间模式和日间模式。使用.read-mode
的类来界定阅读模式。
可以简单的认为,当切换为夜间模式或者阅读模式时,会给页面整体套上一个壳,而我们要做的就是对这个壳底下的元素重新定义样式。此处以对文字页和侧栏的设置为例:
修改 [Blogroot]\themes\butterfly\source\css\custom.css
。
夜间模式:
[data-theme="dark"] #aside-content .card-widget{ background: rgba(0, 0, 0, 0.5)!important; } [data-theme="dark"] div#post{ background: rgba(0, 0, 0, 0.5)!important; }
|
阅读模式:
.read-mode #aside-content .card-widget{ background: rgba(158, 204, 171, 0.5)!important; } .read-mode div#post{ background: rgba(158, 204, 171, 0.5)!important; }
|
夜间模式下的阅读模式:
[data-theme="dark"] .read-mode #aside-content .card-widget{ background: rgba(0, 0, 0, 0.5)!important; color: #ffffff; } [data-theme="dark"] .read-mode div#post{ background: rgba(0, 0, 0, 0.5)!important; color: #ffffff; }
|
4.友链卡片样式魔改
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
div.flink-list-item{ border: 1px solid #98d3d370; box-shadow: 5px 5px 5px #a0a0a0; background-color:#00000000; background-image:-webkit-gradient(linear,leftbottom,righttop,color-stop(0.32,#ce1ef170),color-stop(0.66,#0fe9e970),color-stop(0.83,#3e76aa70)); background-image:-webkit-linear-gradient(45deg,#ce1ef170,#0fe9e970,#3e76aa70); background-image:-moz-linear-gradient(45deg,#ce1ef170,#0fe9e970,#3e76aa70); }
div.flink-list-item::before{ background: rgba(0, 0, 0, 0.2)!important; }
span.flink-item-name:hover{ color: #e95f10e1; }
[data-theme="dark"] div.flink-list-item{ box-shadow: rgba(102, 218, 215, 0.8) 2px 2px 8px 0px !important; } [data-theme="dark"] div.flink-list-item:hover{ box-shadow: rgba(102, 218, 215, 0.8) 0px 0px 2px 0px !important; }
[data-theme="dark"] div.flink-list-item::before{ background: rgba(255, 255, 255, 0.2)!important; }
|
5.修改博客字体样式
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
@font-face { font-family: 'tzy'; src: url('https://cdn.jsdelivr.net/gh/tzy13755126023/BLOG_SOURCE/font/ZhuZiAWan.woff2'); font-display: swap; }
body, .gitcalendar { font-family: tzy !important; }
|
6.修改朋友圈样式
前提是增加了朋友圈功能,修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
div#fMessageBoard{ height: 280px; } div.fActiveFriend.fItem{ margin-top: 10px; } div.fArticleNum.fItem{ margin-bottom: 10px; } span#rankByCreated{ line-height: 30px; } span#rankByUpdated{ line-height: 30px; }
[data-theme="dark"] div#fMessageBoard{ background-color: rgba(21, 21, 21, 0.5); color: #eeeeee; height: 280px; box-shadow: rgba(102, 218, 215, 0.5) 2px 2px 5px 0px; } [data-theme="dark"] div.fMessageItem{ background-color: rgba(21, 21, 21, 0.5) !important; box-shadow: rgba(222, 221, 174, 0.5) 0px 0px 5px 0px inset !important; } [data-theme="dark"] div.fActiveFriend.fItem{ background-color: rgba(0, 0, 0, 0) !important; margin-top: 10px; } [data-theme="dark"] div.fErrorSite.fItem{ background-color: rgba(0, 0, 0, 0) !important; } [data-theme="dark"] div.fArticleNum.fItem{ background-color: rgba(0, 0, 0, 0) !important; margin-bottom: 10px; } [data-theme="dark"] span#rankByCreated{ line-height: 30px; } [data-theme="dark"] span#rankByUpdated{ line-height: 30px; } [data-theme="dark"] div.fArticleItem{ background-color: rgba(21, 21, 21, 0.5) !important; color: #eeeeee !important; box-shadow: rgba(102, 218, 215, 0.5) 2px 2px 5px 0px !important; } [data-theme="dark"] div.fArticleItem:hover{ box-shadow: rgba(102, 218, 215, 0.5) 0px 0px 2px 0px !important; } [data-theme="dark"] a.fArticleTitle{ color: #eeeeee !important; } [data-theme="dark"] div#fcircleMoreBtn{ background-color: rgba(21, 21, 21, 0.5) !important; color: #eeeeee !important; box-shadow: rgba(102, 218, 215, 0.5) 2px 2px 5px 0px !important; } [data-theme="dark"] div#fcircleMoreBtn:hover{ box-shadow: rgba(102, 218, 215, 0.5) 0px 0px 2px 0px !important; }
|
7.修改gitalk评论样式
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
div.gt-comment-body.markdown-body{ font-family: 'tzy'; } div.gt-comment-content{ background-color: rgba(255, 255, 255, 0.5) !important; box-shadow: rgba(17, 104, 235, 0.8); border-radius: 5px; } div.gt-comment.gt-comment-admin .gt-comment-content{ background-color: rgba(255, 255, 255, 0.5); box-shadow: rgba(17, 104, 235, 0.8); border-radius: 5px; } div.gt-comment-content:hover{ box-shadow: rgba(170, 170, 170, 0.8) 2px 2px 10px 0px !important; } [data-theme="dark"] div.gt-comment-body.markdown-body{ color: rgba(255, 255, 255, 0.9) !important; font-family: 'tzy'; } [data-theme="dark"] div.gt-comment-content{ background-color: rgba(21, 21, 21, 0); box-shadow: rgba(17, 104, 235, 0.8); border-radius: 5px; } [data-theme="dark"] div.gt-comment.gt-comment-admin .gt-comment-content{ background-color: rgba(21, 21, 21, 0); box-shadow: rgba(17, 104, 235, 0.8); border-radius: 5px; } [data-theme="dark"] div.gt-comment-content:hover{ box-shadow: rgba(139, 182, 247, 0.8) 2px 2px 10px 0px !important; }
|
8.修改本地搜索样式
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
div#local-search .search-dialog{ border-radius: 10px; color: rgb(20, 20, 20); border: 1px solid #98d3d370; background-color:#ffffffaa; background-image:-webkit-gradient(linear,leftbottom,righttop,color-stop(0.32,#ce1ef170),color-stop(0.66,#0fe9e970),color-stop(0.83,#3e76aa70)); background-image:-webkit-linear-gradient(45deg,#ce1ef170,#0fe9e970,#3e76aa70); background-image:-moz-linear-gradient(45deg,#ce1ef170,#0fe9e970,#3e76aa70); } a.search-result-title{ font-size: 18px; } [data-theme="dark"] a.search-result-title{ color: rgb(37, 37, 37) !important; } div.local-search__hit-item a:hover{ color: rgb(230, 84, 17) !important; } span.search-keyword{ color: rgb(230, 17, 45) !important; } p.search-result{ font-size: 17px; } div.search-dialog__title{ color: rgb(230, 17, 45) !important; } div.search-dialog span.search-close-button:hover { color: #f84040; }
|
9.页脚蝴蝶振翅动画
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
.copyright svg{ animation:butterfly 1s linear infinite alternate; } @keyframes butterfly { from { transform:rotateY(70deg); } to { transform:rotateY(0deg); } }
|
10.修改iconfont样式
修改[Blogroot]\themes\butterfly\source\css\custom.css
,新增如下样式:
.icon { width: 1em; height: 1em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; }
|
未完。待续~~~
如有错误,欢迎评论区留言!