通过角度材质主题设置文本输入颜色

时间:2018-09-21 15:33:03

标签: angular themes angular-material2

我真的对角材料主题非常陌生。实际上是在30分钟前开始的! :)

所以我能够设置主要的,强调的和警告的颜色。

现在我正在尝试在主题中设置文本输入颜色。

不知道如何正确执行操作...

我检查了mat-input元素,发现placeholder标签的颜色是由以下类设置的: mat-form-field-appearance-legacymat-form-field-label

我创建了以下主题文件:

@import '~@angular/material/theming';
// Plus imports for other components in your app.

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat-core();

// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue. Available color palettes: https://material.io/design/color/
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);

// The warn palette is optional (defaults to red).
$candy-app-warn:    mat-palette($mat-amber);

// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);

// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.

.mat-form-field-appearance-legacy .mat-form-field-label {
  color: white;
}
@include angular-material-theme($candy-app-theme);

这根本不影响mat-input占位符的颜色。

所以我试图了解如何正确设置带有主题的输入颜色。

有关此问题的任何想法将不胜感激。

1 个答案:

答案 0 :(得分:1)

请考虑在开始之前先查看Customizing Component Styles指南。

无论如何,您必须使用!important样式,因为Angular Material的样式会覆盖您的样式:

// ...
.mat-form-field-appearance-legacy .mat-form-field-label {
  color: white !important;
}