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

Enhancing dark-mode themes with color-scheme implementation in CSS #2132

Closed
GiorgioReale opened this issue Jul 18, 2023 · 2 comments · Fixed by #2134
Closed

Enhancing dark-mode themes with color-scheme implementation in CSS #2132

GiorgioReale opened this issue Jul 18, 2023 · 2 comments · Fixed by #2134
Labels
A-Style Area: Style (CSS, etc.) C-enhancement Category: Enhancement or feature request

Comments

@GiorgioReale
Copy link
Contributor

GiorgioReale commented Jul 18, 2023

Problem

When mdBook is displayed with a dark theme, some elements of the browser remain rendered in a light theme, which is unfortunate since most browsers support the implementation of color-scheme: light | dark; in CSS.

Example:
Currently, in the dark theme, the scrollbars are displayed in a light color.

However, it would be sufficient to implement color-scheme: dark; on the html tag to make them dark for browsers that support it (e.g., Chrome or Edge - not Firefox).

Proposed Solution

To resolve these issues, the following two steps can be taken:

  1. Add the following CSS rules for each theme class in the src/theme/css/variables.css file:
.coal {
  --color-scheme: dark;
}

.navy {
  --color-scheme: dark;
}

.ayu {
  --color-scheme: dark;
}

/* For completeness, declare the rule also for light themes. */
.light {
  --color-scheme: light;
}

.rust {
  --color-scheme: light;
}
  1. Add the following CSS rule for :root in the src/theme/css/general.css file:
:root {
  color-scheme: var(--color-scheme);
}

Notes

No response

@GiorgioReale GiorgioReale added the C-enhancement Category: Enhancement or feature request label Jul 18, 2023
@ehuss
Copy link
Contributor

ehuss commented Jul 18, 2023

Sounds like a good idea to me, do you want to open a PR to fix it?

@ehuss ehuss added the A-Style Area: Style (CSS, etc.) label Jul 18, 2023
@GiorgioReale
Copy link
Contributor Author

@ehuss sure, i can open a pull request to fix it in the next few hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Style Area: Style (CSS, etc.) C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants