Prog.秀莲
Prog.秀莲Lv1
搞主题切换真的绕不开CSS变量和Sass混入…

$themes: (
  light: (
    bg: #fff,
    text: #333
  ),
  dark: (
    bg: #333,
    text: #fff
  )
);

@mixin themeify {
  @each $theme, $map in $themes {
     & {
      @content($map);
    }
  }
}

@function themed($key, $map) {
  @return map-get($map, $key);
}

body {
  @include themeify using ($map) {
    background-color: themed('bg', $map);
    color: themed('text', $map);
  }
}


#前端主题切换实战#