简体   繁体   中英

How do I use a material theme colors in my css in Angular2?

Let's say I need to use the mat-primary color as a background of a div using a css/sass class, how do i reference it? I thought something like:

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

.a-class{
  background-color: $mat-primary;
}

but miserably fails.

You have to first import the theme with

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

Then you have to define a mixin like

@mixin primary-color($theme) {

  $primary: map-get($theme, primary);

  //Then you can use `mat-color` to get the `primary` color
  .a-class {
    background-color: mat-color($primary);
  }
}

Reference Link: Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM