#
VitePress真是太好用了
2025-08-27
VitePress 主题色
通过 var.css 配置 VitePress 主题色,定制网站整体配色方案。VitePress 使用 CSS 变量定义主题色,通过覆盖默认变量值,可以轻松修改网站的主题色调、品牌颜色和深色模式配色。
在theme目录下新建style文件夹,然后新建index.css和var.css。
.
├─ docs
│ ├─ .vitepress
│ │ └─ config.mts
│ │ └─ theme
│ │ └─ style
│ │ └─ index.css
│ │ └─ var.css
│ └─ index.md
└─ node_modules分别复制代码并粘贴
index.css
/* index.css */
@import './var.css';var.css
/* var.css */
:root {
--vp-c-brand-1: #18794e;
--vp-c-brand-2: #299764;
--vp-c-brand-3: #30a46c;
}
.dark {
--vp-c-brand-1: #3dd68c;
--vp-c-brand-2: #30a46c;
--vp-c-brand-3: #298459;
}
/* 以前的vp-c-brand已弃用 */
:root {
/* hero标题渐变色 */
--vp-home-hero-name-color: transparent;
--vp-home-hero-name-background: -webkit-linear-gradient(120deg, #bd34fe, #41d1ff);
/*hero logo背景渐变色 */
--vp-home-hero-image-background-image: linear-gradient(-45deg, #bd34fe 50%, #47caff 50%);
--vp-home-hero-image-filter: blur(40px);
}
/* 也可自行单独修改brand按钮 */
/* :root {
--vp-button-brand-border: #F6CEEC;
--vp-button-brand-text: #F6CEEC;
--vp-button-brand-bg: #D939CD;
--vp-button-brand-hover-border: #F6CEEC;
--vp-button-brand-hover-text: #fff;
--vp-button-brand-hover-bg: #D939CD;
--vp-button-brand-active-border: #F6CEEC;
} */然后将修改好的样式引入index.ts
/* .vitepress/theme/index.ts */
import DefaultTheme from 'vitepress/theme'
import './style/index.css'
export default {
extends: DefaultTheme,
} 本文由 DoubleSpirit121 原创
采用 CC BY-NC-SA 4.0 协议进行许可
TAGS:
VitePress 1.6.3
0 评论