I'm working on an application where depending on a class on the HTML element, a different color theme should be applied. We're using postCSS and need to support IE11.
I've tried two different plugins, postcss-custom-properties
and postcss-css-variables
, which both give similar results....
For example, when given the following input:
:root {
--color: red;
}
:root.green {
--color: green;
}
p {
color: var(--color);
}
postcss-css-variables
would produce the following output:
p {
color: red;
}
But I was hoping for output like this:
p {
color: red;
}
html.green p {
color: green;
}
With the actual outcome, I don't think it would be possible to create a color theme that can be switched by toggling a class.
PostCSS solutions for theming seem to focus on producing a theme during build-time. In our application each user can choose its own color theme, and should be able to switch theme without refreshing the page. As such it needs to be a CSS class based solution and all color/class permutations should be in the served CSS.
Is it possible to achieve what I am looking for using postCSS?
(if only we could ditch IE11 support.... then we could just rely on css variables...)