Alternative fonts for headers #7834
LandonTClipp
started this conversation in
Show and tell
Replies: 1 comment 4 replies
-
@LandonTClipp If you're already using a |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to share how I added support in the theme configuration to specify an alternative font for header sections. mkdocs-material currently does not support this and I couldn't find any other discussions on how to do this, so I'm writing this show-and-tell so all future generations can learn! 😄
This follows the configuration pattern already established here.
Overridding
main.html
Place a file at
overrides/main.html
and add the following content:This is essentially the same as the theme defaults, but it adds the
--md-header-font
variable and modifies the stylesheet URL to grab whatever theheader
jinja variable is set to.Create additional CSS
Now that the variable has been added to the root CSS section, you can add more CSS selectors to propagate the font family you've defined. Here is my
extra.css
:The theme uses these
--md-{text,code}-font-family
CSS variables to set defaults if the--md-{text,code}-font
fonts are not available in the deployed site, so we do the same in thebody
selector for the header variable. We then modify theh2,h3,h4,h5,h6
styles to select thefont-family
from the--md-header-font-family
variable that was defined.I also added some additional coloring to the headers, but this is optional.
Apply the configuration in
mkdocs.yml
And voila, we can specify the header font in the theme configuration:
You can see the result in my site here:
Beta Was this translation helpful? Give feedback.
All reactions