-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Introduce CSS variables to make color customization more flexible #1297
Labels
change request
Issue requests a new feature or improvement
Comments
Thanks for your work on this issue! As discussed in #1293, I will evaluate this in the light of the next big iteration of Material (v5). |
squidfunk
changed the title
Support Custom Colors Outside of the Material Design Color Palette
Introduce CSS variables to make color customization more flexible
Oct 9, 2019
Tracked in #1409 |
Implemented in 309c2b7 with the help of @Stanzilla 🐲 Will be part of the next beta (or maybe even RC) |
Material for MkDocs 5.0.0rc1 is out which fixes this issue 😀 Let's test and improve it together! |
Thanks, I will look into it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I checked that...
See further discussion below.
Description
This issue should track the progress and ideas of #1293.
Motivation
It is currently possible to change the primary and accent color by using a color palette with predefined names. Behind those names are several color values provided that allow for over 300 color compositions.
However, if you require a specific (i.e. custom) color, there are two options available, both of which have their downsides and require to fork this repository to do the adjustments.
assets/stylesheets/application-palette.3e3d1dff.css
which is error prone._config.scss
which in term provides a more complete and failsafe environment, but requires to build the project.Both solutions require to take the current version of mkdocs-material and incorporate a snapshot of its files within your own documentation. This then receives only manual update by the maintainer of these documentations.
Idea
The color palette allows for generation of a stylesheet, as the colors are described staticly. However, CSS now allows for defining variables that are evaluated at runtime and thus different from Sass variables, which are evaluated at compile time.
The basic idea is to use those variables and have only one definition of the stylesheet which then dynamically adjusts to the variables. This simplifies the code and requires for the above color palettes to only change the variable definitions. Secondly, this allows for integrating a theme as described #1266.
As the defined colors in the palette are written to the HTML body, the next step would be to change read the HTML attributes
data-md-color-primary
anddata-md-color-accent
and update the CSS variables.Problem
Like I described above, having static color values allows for defining the stylesheet at compile time of mkdocs-material. Using custom values requires to do this dynamically. Using JavaScript, as the current solution suggests, seems agreeably the wrong approach.
Solution
@squidfunk suggested a solution which uses a similar system on how the values of the
mkdocs.yml
are injected into the HTML files.The template would use an inline style to firstly lookup the value in the provided color palette or—if not found—inline the value as literal.
This might be possible with fallback values where
--md-color-${palette-name}
would have been injected from the generated color palette similar to$clr-red-400
.Further discussion
The provided mockup and the solution discussed above will require some more thought:
Screenshots / Mockups
A working draft of the idea is described in PR #1293 which essentially allows for providing HEX colors instead of names:
The text was updated successfully, but these errors were encountered: