Scss主题取决于带有预定义变量的身体类别

时间:2018-11-28 11:54:02

标签: sass theming

我想要一个复选框,当您单击它时,将类添加到body标签,例如“ dark-theme”或“ light theme”。问题是主题要求在我设置了所有元素样式之后出现,现在更改每个元素样式可能会自杀。请帮助

$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 个答案:

答案 0 :(得分:1)

您可以为每个主题用不同的颜色(以及其他可编辑的内容)两次编译css文件。

带有所有“轻”变量light-theme.scss的文件:

$color: black;
$background: white;

带有所有“暗”变量dark.scss的文件:

$color: white;
$background: black;

包含所有样式_style.scss的文件:

@import '_button.scss'; // If you are importing something
@import '_header.scss';

element{
  color: $color;
  background: $background;
}

生成所有主题的文件themes.scss

.light {
  @import 'light-theme';
  @import '_styles';
}

.dark {
  @import 'dark-theme';
  @import '_styles';
}

Css输出:

.dark element {
  color: white;
  background: black;
}

.light element {
  color: black;
  background: gray;
}