1.8 KiB
1.8 KiB
title, categories, series, tags, abbrlink, date
| title | categories | series | tags | abbrlink | date |
|---|---|---|---|---|---|
| 自定义字体 | 网站 | webcustom | 网站 | b5601a7e | 2025-08-12 10:57:21 |
{% series webcustom %} 今天感觉网站的字体有些不好看,想换一下,搜索发现网站用woff或者woff2字体,在手机端和电脑都能完美显示
选择字体
首先在网上查找自己喜欢的字体,这里有一个网站 {% link 中文开源字体集 Open Source Fonts Collection for Chinese,开源字体,https://drxie.github.io/OSFCC/ %} 找到一个自己喜欢的,如果有woff或者woff2格式下载下载保存。没有也没关系,转换网站: {% link 转换网站,ttf2woff2,https://products.groupdocs.app/zh/conversion/ttf-to-woff2 %} 利用这个网站把下载的ttf字体文件转换成woff2格式。
添加字体
新建一个css文件
@font-face {
font-family: 'CascadiaCodePL';
font-display: swap;
src: url('/butterflyChange/fonts/font.woff2') format("woff2");
}
其中font.woff2改成自己的文件名。
其他字体格式参考
@font-face {
font-family: 'webfont';
font-display: swap;
src: url('.eot'); /*IE9*/
src: url('.eot') format('embedded-opentype'), /* IE6-IE8 */
url('.woff2') format('woff2'),
url('.woff') format('woff'), /*chrome、firefox */
url('.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
url('.svg') format('svg'); /* iOS 4.1- */
}```
然后在`_config.butterfly.yml`里面引用这个css
```yml
- <link rel="stylesheet" href="/css/font.css">
在主题文件的font配置区域修改字体:
font:
global_font_size: 110%
code_font_size: 100%
font_family: # ,全局字体,不带后缀名
code_font_family: # 这是代码使用的字体
参考链接
{% link Ordis的博客,ordis,https://blog.imbhj.com/archives/0rIzmBIn %}