为Hexo的Redefine主题设定字体样式
Hexo Theme Redefine 字体样式自定义部署文档
本次部署目的
Redefine部分字体的设置项目相当难找。因为以后的我会忘记这次部署,所以还得记录下本次操作步骤。
这篇文档记录了自定义 Hexo Theme Redefine 主题的字体样式,包括文章正文、标题、页面标题等各种文本元素的字体大小、行高和间距,以提升网站的视觉体验和可读性。
操作步骤
1. 修改主题配置文件
在 _config.yml 中调整基础字体设置:
1 | articles: |
2. 使用 inject 功能注入自定义样式
通常来说这些项目不会用到(除了文章页面标题相对较难找到)
在 _config.yml 中启用 inject 功能:
1 | inject: |
3. 重新生成站点
1 | hexo clean && hexo generate |
有效的字体设置项目
配置文件中的字体设置
| 配置项 | 位置 | 作用 | 默认值 |
|---|---|---|---|
articles.style.font_size |
_config.yml |
正文字体大小 | 16px |
articles.style.line_height |
_config.yml |
正文行高 | 1.5 |
articles.style.headings_top_spacing |
_config.yml |
各级标题顶部间距 | h1: 3.2rem, h2: 2.4rem… |
home_banner.text_style.title_size |
_config.yml |
主页大标题字体大小 | 2.8rem |
home_banner.text_style.subtitle_size |
_config.yml |
主页副标题字体大小 | 1.5rem |
CSS 选择器对应的字体设置
| 选择器 | 作用 | 默认字体大小 | 文件位置 |
|---|---|---|---|
.markdown-body |
文章正文内容 | 16px | source/css/common/markdown.styl 3 |
.markdown-body h1 |
正文 H1 标题 | 3.2rem | source/css/common/markdown.styl 4 |
.markdown-body h2 |
正文 H2 标题 | 2.5rem | source/css/common/markdown.styl 5 |
.markdown-body h3 |
正文 H3 标题 | 1.8rem | source/css/common/markdown.styl 6 |
.markdown-body h4 |
正文 H4 标题 | 1.5rem | source/css/common/markdown.styl 7 |
.markdown-body h5 |
正文 H5 标题 | 1.28rem | source/css/common/markdown.styl 8 |
.markdown-body h6 |
正文 H6 标题 | 1.2rem | source/css/common/markdown.styl 9 |
.post-page-container h1:first-child |
文章页面标题 | 3.2rem | 通过继承默认 h1 样式 |
.home-article-title |
主页文章列表标题 | 1.4rem | source/css/layout/home-content.styl 10 |
.page-title-header |
页面标题(如归档页) | 3.2rem | source/css/layout/page.styl 11 |
字体变量定义
| 变量名 | 作用 | 默认值 | 文件位置 |
|---|---|---|---|
$default-article-font-size |
默认正文字体大小 | 16px | source/css/common/variables.styl 12 |
$default-line-height |
默认行高 | 1.5 | source/css/common/variables.styl 12 |
$article-title-font-size |
文章标题字体大小 | 3.2rem | source/css/layout/article-content.styl 13 |
重要说明
- 配置文件 vs CSS 选择器:
font_size配置只影响.markdown-body的字体大小,不影响标题 12 - 文章页面标题特殊性:使用
.post-page-container h1:first-child选择器,因为文章标题是容器内的第一个 h1 元素 - 响应式设计:主题包含响应式设计,在平板和移动设备上会自动调整字体大小 14
- 优先级:使用
!important确保自定义样式优先级足够高
Notes
- 修改配置文件后需要重新生成站点
- inject 功能是推荐的自定义方式,不会影响主题源文件
- 可以使用浏览器开发者工具检查元素的确切类名
- 建议使用相对单位(rem)而非绝对单位(px)以保持响应式设计
Wiki pages you might want to explore:
- Article and Content Layout (EvanNotFound/hexo-theme-redefine)
- Layout System (EvanNotFound/hexo-theme-redefine)
Wiki pages you might want to explore:
Citations
File: _config.yml (L273-289)
1 | # Set the styles of the article |
File: _config.yml (L409-422)
1 | # INJECT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start |
File: source/css/common/markdown.styl (L1-4)
1 | .markdown-body |
File: source/css/common/markdown.styl (L123-124)
1 | +redefine-tablet() |
File: source/css/common/markdown.styl (L126-137)
1 | h1, .h1 |
File: source/css/common/markdown.styl (L139-151)
1 | h2, .h2 |
File: source/css/common/markdown.styl (L153-163)
1 | h3, .h3 |
File: source/css/common/markdown.styl (L165-174)
1 | h4, .h4 |
File: source/css/common/markdown.styl (L176-185)
1 | h5, .h5 |
File: source/css/common/markdown.styl (L187-196)
1 | h6, .h6 |
File: source/css/layout/home-content.styl (L55-67)
1 | .home-article-title |
File: source/css/layout/page.styl (L3-8)
1 | .page-title-header |
File: source/css/common/variables.styl (L139-142)
1 | $temp-default-article-font-size = hexo-config('articles.style.font_size') |
File: source/css/layout/article-content.styl (L5-5)
1 | $article-title-font-size = 3.2rem |
- Title: 为Hexo的Redefine主题设定字体样式
- Author: MagicNue
- Created at : 2026-04-09 22:38:00
- Updated at : 2026-04-09 14:33:16
- Link: https://magicnue.top/posts/记录/为Hexo的Redefine主题设定字体样式/
- License: This work is licensed under CC BY-NC-SA 4.0.