Sass variables require colors to be imported
See original GitHub issueHello. I’d like to import variables to my website’s sass file but after adding:
@import "../bower_components/materialize/sass/components/_variables.scss";
I’m getting following error:
Error: $color: 'color("materialize-red", "lighten-2")' is not a color for `lighten'
on line 37 of /opt/lampp/htdocs/materialcv/static/bower_components/materialize/sass/components/_variables.scss
from line 10 of /opt/lampp/htdocs/materialcv/static/sass/page.scss
If I import materialize colors component before variables it all will work well. The problem is I don’t want to include colors for the second time becuase they are already included in materialize. They are 1.6k lines trash in my output css file
Sass 3.4.21 (Selective Steve) materialize#0.97.7
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
how to import colors in variables.scss - Stack Overflow
I have a scss file with some colors; how I can import and use them in variables.scss in ionic angular? $colors: ( carscolor:...
Read more >Sass: @import
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining ......
Read more >The New SASS Module System: Out with @import, In with @use
For example, you can reference a private color variable named $_primaryRed in your _buttons.scss partial which will only be accessible in that ...
Read more >Sass @import and Partials - W3Schools
You can create small files with CSS snippets to include in other Sass files. Examples of such files can be: reset file, variables,...
Read more >SASS variables - Vuetify
This is required for custom SASS variables to work. ... SCSS has different line endings than SASS // and needs a semicolon after...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Wrapping the function that creates these colors in a variable could solve the problem. We would have to split the current
_colors.scss
file into two files:_colors.scss
and_color-palette.scss
.The palette would only contain the palette and the sass function, that allows you to access the colors via
color("name_of_color", "type_of_color")
. The_colors.scss
file would only contain the if statement, that optionally generates all the colors and the primary/secondary classes.With these changes, you could easily access the palette by importing it before anything else.
E.g.: _variables.scss:
_colors.scss:
In addition to that, I think it would make sense to provide classes that apply the primary and secondary class:
My solution was to create a new partial - components/_palette.scss. - and move all the lists (i.e.
$materialize-red: (...
and the@function color()
definition in _color.scss to the new file. Now, all _color.scss does is create css classes.In materialize.scss the line
@import "components/palette";
was added above@import "components/color";
The result is that Materialize compiles as it should.Now, to use Materialize variables in a site’s css: (without duplicating the color classes) do this.
materialize#0.97.7 If you want a pull request let me know.