Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite SCSS variables when compiling to CSS

I'm trying to use jqtouch theming which is based on SASS and COMPASS. I have a file custom.scss with the most simple code, one import and one variable to overwrite:

@import 'jqtouch';  // Override variables $base-color: #fe892a;/* The default base which is later used for toolbar, list, and button backgrounds.*/ 

When I now compile the scss file to css, it will basically just generate the jqtouch css with my filename. The color specification is nowhere to be seen, although the variable is definitley correct per documentation (Official Guide) and in the jqtouch.scss file, which I import for costumizing.

I'm running Sass 3.2.9 and Compass 0.12.2 on a Windows machine.

I've tried it with more variables and different file imports, but the result is always, that my override values are not incorporated.

The ruby config file for compass seems to be unsuspicious.

Does anyone have an idea what goes wrong in the process so that my override values are ignored?

like image 362
bouscher Avatar asked Jun 13 '13 14:06

bouscher


People also ask

How do I override a SCSS variable?

Override Variables scss” in the “scss” folder, which contains all variables used in Bootstrap. Now, add the “abstracts” name folder in your scss folder and create “_custom-variables. scss” in that folder. Now, open Bootstrap > scss > “_variables.

Can you change SCSS variable value dynamically?

SCSS is compiled to CSS during compile time, and SCSS variables are replaced with resolved value during compile time, which means there is no way to change the variable during run time. However, CSS variables just sits there during run time, and you can dynamically CRUD them during run time with JavaScript (Web API).

Can I use CSS instead of SCSS?

SCSS contains all the features of CSS and contains more features that are not present in CSS which makes it a good choice for developers to use it. SCSS is full of advanced features. SCSS offers variables, you can shorten your code by using variables. It is a great advantage over conventional CSS.

Is SCSS compiled to CSS?

scss already imports all other scss files of template. So when any SCSS file in the scss folder is updated, it will be compiled to . css files. Now, you can start working with SCSS files.


1 Answers

You're setting the color after it has already been used. Basically, what you're trying to do is this:

$color: red;  .foo {     background: $color; }  $color: green; 

Depending on how jqtouch is written, you might not be able to modify the colors at all. You need the variables to be set as a default in order to overwrite them ahead of time:

$color: green; $color: red !default; // red is only used if $color is not already set  .foo {     background: $color; // color is green } 

So your code should be written as such:

// Override variables $base-color: #fe892a;/* The default base which is later used for toolbar, list, and button backgrounds.*/  @import 'jqtouch'; 
like image 150
cimmanon Avatar answered Sep 24 '22 00:09

cimmanon