[英]Angular Material - How to use all colors in HTML of active theme?
If I import the SCSS theming functions to my component's stylesheet: 如果将SCSS主题功能导入到组件的样式表中:
@import '~@angular/material/theming';
@import 'src/my-mat-color-palette';
I can access all theme colors / hues like this: 我可以像这样访问所有主题颜色/色调:
background: mat-color($my-pallete, 700);
color: mat-contrast($my-pallete, 700);
In template file I am also able to set primary
, accent
and warn
theme color for components that have the @Input() color
property: 在模板文件中,我还可以为具有
@Input() color
属性的组件设置primary
, accent
和warn
主题颜色:
<button mat-button color="accent">Click me!</button>
But how can I set all the other colors / hues in template file? 但是,如何在模板文件中设置所有其他颜色/色相? Are they already provided as classes (something like
mat-primary-300
) or do I have to declare them myself? 它们是否已经作为类提供(例如
mat-primary-300
),还是我必须自己声明它们?
As of now, there isn't any direct way in material 2 (like md-color in angular material) to use hues, however you can use following work around: Create style classes as follows: 到目前为止,材质2中没有任何直接的方式(如角材质中的md-color)使用色相,但是您可以使用以下解决方法:创建样式类,如下所示:
.primary-light-bg {
background-color: mat-color($primary, lighter);
}
.primary-dark-bg {
background-color: mat-color($primary, darker);
}
.primary-bg-A200 {
background-color: mat-color($primary, A200);
}
.primary-bg-A300 {
background-color: mat-color($primary, A400);
}
You can also use other color swatches. 您还可以使用其他颜色样本。 For eg:
例如:
.purple-bg-600 {
background: mat-color($mat-purple, 600);
}
.green-bg-600 {
background: mat-color($mat-green, 600);
}
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.