请通读angular-material theming documentation
这包含了你的Angular material 组件主题的完美说明,目前,下面是一个工作的例子,当我使用green-palette
来设计一个绿色主题的所有组件的样式.这将帮助您达成您的最终解决方案!
主旋律
...
$主旋律-primary: mat.define-palette(mat.$green-palette);
$主旋律-accent: mat.define-palette(mat.$green-palette);
...
full 主旋律 scss
// Custom Theming for Angular Material
// For more information: https://material.angular.io/guide/theming
@use '@angular/material' as mat;
// 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 主旋律 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/
$主旋律-primary: mat.define-palette(mat.$green-palette);
$主旋律-accent: mat.define-palette(mat.$green-palette);
// you can also do below
// $主旋律-accent: mat.define-palette(mat.$green-palette, A200, A100, A400);
// The warn palette is optional (defaults to red).
$主旋律-warn: mat.define-palette(mat.$red-palette);
// Create the 主旋律 object. A 主旋律 consists of configurations for individual
// theming systems such as "color" or "typography".
$主旋律: mat.define-light-主旋律(
(
color: (
primary: $主旋律-primary,
accent: $主旋律-accent,
warn: $主旋律-warn,
),
typography: mat.define-typography-config(),
)
);
// Include 主旋律 styles for core and each component used in your app.
// Alternatively, you can import and @include the 主旋律 mixins for each component
// that you are using.
@include mat.all-component-主旋律s($主旋律);
HTML
<div class="label-input-block top-centre-form">
<mat-form-field class="green-input" name="gadsCustomerId" id="gadsCustomerId">
<mat-label>Select accounts</mat-label>
<mat-select multiple>
<mat-option *ngFor="let cid of customer_list" [value]="cid.id">
{{ cid.account_name }} [{{ cid.id }}]
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="label-input-block top-centre-form">
<mat-form-field class="green-input">
<mat-label class="green-input">From Days Ago</mat-label>
<input
type="number"
class="green-input"
name="fromDaysAgo"
id="fromDaysAgo"
matInput
/>
</mat-form-field>
</div>
<mat-label class="green-input">checkbox</mat-label>
<mat-checkbox class="example-margin">Check me!</mat-checkbox>
stackblitz