如何在 Angular2 的 css 中使用材质主题颜色? [英] How do I use a material theme colors in my css in Angular2?

查看:38
本文介绍了如何在 Angular2 的 css 中使用材质主题颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要使用 mat-primary 颜色作为使用 css/sass 类的 div 的背景,我该如何引用它?我想过这样的事情:

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;
}

却惨遭失败.

推荐答案

你必须先用

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

然后你必须定义一个像

@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);
  }
}

参考链接:文档

这篇关于如何在 Angular2 的 css 中使用材质主题颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆