如何为 mkdocs-material 指定自定义原色?

How do I specify custom primary color for mkdocs-material?

我正在使用 mkdocs-material 创建文档网站。 如何指定我自己的自定义主色和辅助色?

我不想使用任何现有颜色

我找到路了。

首先在 docs/stylesheets/

中创建一个 extra.css
:root {

    /* Primary color shades */
    --md-primary-fg-color: #861f41;
    --md-primary-fg-color--light: #861f4194;
    --md-primary-fg-color--dark: #ac325a;
    --md-primary-bg-color: hsla(0, 0%, 100%, 1);
    --md-primary-bg-color--light: hsla(0, 0%, 100%, 0.7);
    --md-text-link-color: hsla(231, 48%, 48%, 1);

    /* Accent color shades */
    --md-accent-fg-color: rgb(98, 18, 189);
    --md-accent-fg-color--transparent: hsla(189, 100%, 37%, 0.1);
    --md-accent-bg-color: hsla(0, 0%, 100%, 1);
    --md-accent-bg-color--light: hsla(0, 0%, 100%, 0.7);
  }
  
  :root > * {
  
    /* Code block color shades */
    --md-code-bg-color: hsla(0, 0%, 96%, 1);
    --md-code-fg-color: hsla(200, 18%, 26%, 1);

    /* Footer */
    --md-footer-bg-color: #861f41;
    --md-footer-bg-color--dark: hsla(0, 0%, 0%, 0.32);
    --md-footer-fg-color: hsla(0, 0%, 100%, 1);
    --md-footer-fg-color--light: hsla(0, 0%, 100%, 0.7);
    --md-footer-fg-color--lighter: hsla(0, 0%, 100%, 0.3);
  }

然后在mkdocs.yml

中配置
extra_css:
  - stylesheets/extra.css

注意:使用'--md-text-link-color'设置hyperlink颜色已被'--md-弃用排版颜色'。可以在以下位置阅读所有颜色定义:

https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/_colors.scss

不错,这个对我帮助很大

但是,不要忘记将 extra_css 作为外键

edit_uri: ""
url_start: "..."

# Copyright
copyright: "..."

extra_css: # <-------- HERE
- stylesheets/extra.css 

# Configuration
theme:
  name: material
  custom_dir: material
 ...