Different CSS changes for different color schemes

Hey!

As I’ve been able to understand so far, any change in CSS is applied to both light and dark mode, which doesn’t make much sense.

Most recently, I have to deal with this problem: on dark mode, the wrapped text looks the same color as the wrapper, and if I change it through CSS, the light theme wrapped text will be changed too, but I don’t want that.

image

How can I change the CSS only for one color scheme?

1 Like

If you use the color variables (ie: var(--primary-very-low), var(--secondary-low)) available in your forum’s style guide /styleguide/atoms/colors, then the dark light modes should respect the different variables (you can also see them in the two colour palettes you are using for the dark and light switch). You will need to enable the styleguide enabled setting in admin-settings, and there is also the styleguide admin only setting which limits it to admins only.

2 Likes

The problem is I already made changes that did not respect the color variable set on the style guide (I couldn’t access it through /styleguide/atoms/colors, though). Is there a way to do so without following the variables?

If I understand the issue well, there’s a specific thing to do for this.

I’ve been working on a guide about this, but I’m struggling a bit to merge information so it’s clear enough to directly use the information in a theme, but still explains underlying technical stuff.

To explain how to do it the most clearly as I can…

I suggest you create a theme locally (using Install the Discourse Theme CLI console app to help you build themes will help).
Then, create a common/color_definitions.scss file in your theme, in which you write:

$my-color: dark-light-choose(#FC3468, #FF93AC);

:root {
  --my-color: #{$my-color};
}

Then, in common/common.scss, you can make use of the variable like this:

h1 {
  color: var(--my-color);
}

It will automatically pick the right color when in dark or light mode.

2 Likes