Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

css - SASS: Set variable at compile time

Is it possible to set a sass variable at compile time? I basically want to do this:


$color: red !default;
div#head {

  background-color: $color;

}

When I compile to css I want to set $color to "blue" (preferably from the command line). Has anyone been able to do this?

Thanks, Chris

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

An alternate of command line options is to create other files assigning values to variables.

Assume that your code above is in a file named 'style.scss'. To set $color to "blue", create a file such as:

$color: blue;
@import "style";

and name it to 'blue.scss' for example. Then compile it with below.

sass blue.scss:style.css

When you want to assign another value to the variable, make another file named "green.scss" like:

$color: green;
@import "style";

Then compile it with

sass green.scss:anotherstyle.css

It is bothering somewhat but enables to decide values of variables at compile time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...