Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help] How to add a custom color to the palette ? #874

Closed
JulienBreux opened this issue Sep 5, 2018 · 13 comments
Closed

[help] How to add a custom color to the palette ? #874

JulienBreux opened this issue Sep 5, 2018 · 13 comments

Comments

@JulienBreux
Copy link

Description

Hello, thanks a lot for this beautiful theme :)

My question is really simple:

How to add a custom color to the palette ?

Thanks :)

@squidfunk
Copy link
Owner

You can either do it via custom CSS or theme customization. With custom CSS you have to target all elements on your own. Customization is the better approach. Please see the guide on customization for more information.

@JulienBreux
Copy link
Author

Thanks!

@thetimbecker
Copy link

I'm having trouble overriding <custum_dir>/assets/stylesheets/_config.scss. I copy and pasted it from GitHub then replaced $md-color-primary and $md-color-accent with the colors I wanted. Still no change. Is that file not meant to be overridden? Is there a better way to override the main colors?

@squidfunk
Copy link
Owner

You need to build the theme to use custom colors through SCSS variables. Please see the guide on theme customization

@estan
Copy link

estan commented Jan 21, 2019

Hm, is it possible to perhaps make this a little easier? The docs says "If you want to make more fundamental changes, it may be necessary to make the adjustments directly in the source of the Material theme and recompile it. This is fairly easy.", but I wouldn't call just tweaking the md-color-primary and md-color-accent a fundamental change.

I think it's something that quite a few users would want to do (for example to fit some company colors), and having to set up essentially a dev environment and rebuild the entire theme just to do that is a little awkward. If it's not really feasible technically, I understand that and you can ignore this comment :)

@squidfunk
Copy link
Owner

squidfunk commented Jan 21, 2019

Well, there are two ways:

  • Change the variables in question and recompile the theme (as you mentioned)
  • Define additional CSS and override all elements one-by-one

Most themes don't even have the first option as they have no build step. If you come up with an easier way that is still maintainable, I'm happy to integrate it.

@estan
Copy link

estan commented Jan 21, 2019

@squidfunk Thanks for the quick answer (!). However, I just found out that it's as simple as

theme:
  name: 'material'
  palette:
    primary: 'blue grey'
    accent: 'deep orange'

in the mkdocs.yml to tweak the primary and accent colors. This is great and very easy, I don't know why it's not in the customization docs at https://squidfunk.github.io/mkdocs-material/customization/ :)

@squidfunk
Copy link
Owner

Oh, I thought you already knew that. It's not in the customization docs because it's considered configuration and therefore listed in the getting started guide

@estan
Copy link

estan commented Jan 21, 2019

@squidfunk Bah, I went straight for "Customization" and totally missed this. Thanks. I see now though that this must be a named color from the Material Design color palette, e.g. "#abcdef" would not work? (would require theme rebuilding).

@squidfunk
Copy link
Owner

That is correct. Material provides shades for all colors from the Material Design color palette. In order to use custom colors you need to follow one of the steps outlined above. Note that when you decide on customization and define the variables, the theme will also adjust all derived colors (i.e. darker and lighter shades) from the primary colors which you would have to do on your own when overriding with custom CSS.

@estan
Copy link

estan commented Jan 21, 2019

Yes, makes total sense. Thanks.

@estan
Copy link

estan commented Jan 21, 2019

(and I see no obvious way of simplifying adding a custom color, due to the static nature of CSS)

@squidfunk
Copy link
Owner

We've been iterating on this topic for quite some time ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants