This is an old project. The theme adds a class to body or another root element. I need to style fonts, backgrounds, based on the theme, but this often leads to structures as:
.theme-light {
...
.elem1 {
...
.elem2 {
color: black;
and duplicate code for theme-dark. Or, the use of !important which we all know should be...prosecuted by law. The ideal selector would be something based on parent, as:
.elem2 {
& <??? > .theme-light {
color: black;
} ....
.elem2 {
& .theme-dark {
color: white;
}
but that is just not possible.
The best way is to use css vars (that will be resolved during runtime).
If for some reason you can't use css vars or won't re-write large parts of the styles you could limit the changes to those component files you want to update via this method:
EDIT: you probably don't need to capture the current selector in the last example and can just use the ampersand directly: