问题
I want to have checkbox which, when you clicked it add class to body tag for example like 'dark-theme' or 'light theme'. The problem is that theming requirment is appeared after i styled all elements, and it would be suicide to change each element styles now. Please help
$color-white: #ffffff;
$color-black: #000000;
// Dark
$color-green: #328332;
$color-red: #a23232;
$color-background-dark: #212734;
$color-backgound-light: #31394c;
$color-text: rgba(255, 255, 255, 0.3);
$color-text-darker: #B8BCC6;
$color-text-active: #ffffff;
$color-button-primary: #0078ff;
$color-button-primary-text: #ffffff;
$color-button-secondary: rgba(255, 255, 255, 0.3);
$color-button-secondary-text: rgba(255, 255, 255, 0.3);
$color-button-secondary-active: #B8BCC6;
$color-button-secondary-text-active: #B8BCC6;
$color-line: #3d465e;
$color-line-darker: rgba(255, 255, 255, 0.3);
$color-table-dark-row: #2C3345;
// Light
$color-green: #006400;
$color-red: #8b0000;
$color-background-dark: #f5f5f5;
$color-backgound-light: #ffffff;
$color-text: #b3b3b3;
$color-text-darker: #808080;
$color-text-active: #000000;
$color-button-primary: #0078ff;
$color-button-primary-text: #ffffff;
$color-button-secondary: #b3b3b3;
$color-button-secondary-text: #b3b3b3;
$color-button-secondary-active: #808080;
$color-button-secondary-text-active: #808080;
$color-line: #f5f5f5;
$color-line-darker: #b3b3b3;
$color-table-dark-row: #FAFAFA;
回答1:
You can compile css files twice for each theme with different colors (and other editable things).
File with all "light" variables light-theme.scss
:
$color: black;
$background: white;
File with all "dark" variables dark.scss
:
$color: white;
$background: black;
File that contains all you styles _style.scss
:
@import '_button.scss'; // If you are importing something
@import '_header.scss';
element{
color: $color;
background: $background;
}
And file where all themes are generated themes.scss
:
.light {
@import 'light-theme';
@import '_styles';
}
.dark {
@import 'dark-theme';
@import '_styles';
}
Css output:
.dark element {
color: white;
background: black;
}
.light element {
color: black;
background: gray;
}
来源:https://stackoverflow.com/questions/53518881/scss-theming-depends-on-body-class-with-predefined-variables