Setting up SCSS color variables won't work

独自空忆成欢 提交于 2020-06-17 02:08:49

问题


I'd like to define my own color variables in my SCSS, but how?

I checked this website and did everything that is described there.. but it doesn't work.

I have installed a preprocessor already!

Furthermore I tried to create a color-map and access the color with map-get.. doesn't work either.

colors.scss file

$yellow_100: #FFC819;

style.scss file with a colors.scss import

h1 {
    color: $yellow_100;
}

I also tried this:

colors.scss file

$colors: (
    color: #FFBB00
);

style.scss file

h1 {
    color: map-get($colors, color);
}

Neither of them works.


回答1:


  1. Install sass with npm -g install sass
  2. Create these two source files:
// _colors.scss
$yellow_100: #FFC819;

// style.scss
@import './colors';

h1 {
    color: $yellow_100;
}

  1. Execute sass ./style.scss ./output.css to compile your code
  2. Add <link rel="stylesheet" type="text/css" href"[path to output.css]" /> to your HTML


来源:https://stackoverflow.com/questions/55470202/setting-up-scss-color-variables-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!