4

I'd like to change variables in materialize _variables.scss e.g.

$primary-color: color("materialize-red", "lighten-2") !default;
$primary-color-light: lighten($primary-color, 15%) !default;
$primary-color-dark: darken($primary-color, 15%) !default;
/*...*/

In my Vue 2 main.js I include materialize style like this

require('materialize-css/sass/materialize.scss');

Because of !default I guess I need to include my _variables.scss before including materialize, but I don't know how.

So what's the proper way to set my own variables e.g. $primary-color: color("blue", "lighten-2") (I want to use predefined palette from materialize _colors.scss)?

EDIT 1: I installed vue2 with vue-cli

EDIT 2:

Folder structure:

├── build/
├── config/
├── dist/
├── node_modules/
│    ├── materialize-css
├── src/
│    ├── components
│    ├── router
│    └── main.js
├── package.json
└── index.html
6
  • Are you using webpack? If yes then you can import your variables before materialize.scss inside an scss file and then import that file in your code. If not what loader or bundler are you using? Commented Feb 28, 2017 at 6:02
  • @TusharArora Yes, updated question. I tried that earlier but it didn't work. Commented Feb 28, 2017 at 11:22
  • @Traxo I have posted answer but it would be better if you can post more details like your project directory structure. This will help us to troubleshoot the problem in a better way. Commented Feb 28, 2017 at 18:03
  • @geeksal Updated Folder structures with folders/files I think might be relevant. If more info is needed just ask. Commented Feb 28, 2017 at 18:15
  • @Traxo I have updated my answer. Let me know if you have tried it and what was the outcome. Please check whether the files are loaded or not using inspect element. Incorrect file path is one of the most common mistake that we make. Commented Mar 1, 2017 at 13:04

2 Answers 2

6
+50

Before changing any default settings in materialized css; first, you need to import the component for which you want to change the settings for. After this you can override the default settings and then you should import materialize. For example if you want to change default color then create a file for example app.scss then write following code:

//please put the paths as per yours project directory structure
@import "materialize-css/sass/components/color";
$primary-color: color("blue", "lighten-2") !default;
@import 'materialize-css/sass/materialize'    

Note: app.css must be included in your page. As per my example app.css must be in your project root folder i.e. at same level as that of index.html

Now you can load app.scss or app.css in Vue 2 as require('../app.scss');

Visit official materialized github repo for viewing complete source.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a reason that app.scss must be in root, or was that just for example? So far it seems that this approach is working, I'll just take time to test it more before accepting answer.
@Traxo No it is not necessary that app.scss must be in root. It is just for example. But as I have already said you that you should always be careful with the paths. So when you move it to other folder make sure that you update paths accordingly in the file. Yeah! you can take your own time to test.
0

In matrialize 1.0.0 however, follow these guildlines to override materialize colors:

  1. Define the value for the variable that you want to override (eg. $primary-color)
  2. Import the materialize.scss library

The definition of the override values must occur before importing the materialize.scss, that means that you can not use the matrial functions such as color()

Example:

// main.scss - the order of the imports is important !!!
@import './_colors';
@import 'materialize-css/sass/materialize.scss';

// _colors.scss
$primary-color: #03a9f4; //light-blue

1 Comment

This answer is close. However, to use the color() function, you can first import it, like this: @import "../node_modules/materialize-css/sass/components/color-variables"; $primary-color: color("red", "lighten-2"); @import "../node_modules/materialize-css/sass/materialize";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.