简体   繁体   English

角材料步进器更改图标颜色

[英]Angular material stepper change icon color

I am using angular 6 and angular material.我正在使用角 6 和角材料。 i am using mat-stepper from angular material.我正在使用角材料的垫子步进器。 want to change the mat-icon color for default, active and visited steps.想要更改默认、活动和访问步骤的垫子图标颜色。 Can anyone help with this please?任何人都可以帮忙吗?

:host /deep/ mat-horizontal-stepper .mat-horizontal-stepper-header-container .mat-step-icon {
    background-color: "red" !important;
    color: #fff !important;
}

.mat-step-icon-selected,
.mat-step-icon-state-done,
.mat-step-icon-state-edit {
  background-color: "blue";
  color:#fff;
}  

Also tried with this:也试过这个:

/deep/ mat-step-header.mat-horizontal-stepper-header > div.mat-step-icon-selected {
    background-color:'red';
}

But not working但不工作

THanks谢谢

I am able to change the color to red with the following style in the styles.css file at the root of the project rather than the stylesheet of the component我可以在项目根目录下的 style.css 文件中使用以下样式将颜色更改为红色,而不是组件的样式表

.mat-step-header .mat-step-icon-selected, .mat-step-header .mat-step-icon-state-done, 
.mat-step-header .mat-step-icon-state-edit {
    background-color: red !important;
    color: red !important;
}

to hide the numbers inside each step just use display none in the style of the class ng-star-inserted要隐藏每个步骤中的数字,只需在 ng-star-inserted 类的样式中使用 display none

.ng-star-inserted {display: none}

I have tried to use @mruanova's answer and i is great but i only want to make the step red when it is selected.我曾尝试使用@mruanova 的答案,我很棒,但我只想在选中该步骤时将其设为红色。

If you want to apply the red color only when the step is selected, use the below css on the parent style file:如果您只想在选择步骤时应用红色,请在父样式文件上使用以下 css:

    .mat-step-icon-selected {
    background-color: red !important;
    color: red !important;
}

Solution with Style on Component (using View Encapsulation)组件样式解决方案(使用视图封装)

Roughly the same as @mruanova but using view encapsulation so the styles can be on the component eg a-stepper.component.css:与@mruanova 大致相同,但使用视图封装,因此样式可以在组件上,例如a-stepper.component.css:

/**
    Change color of stepper icon to green, when completed.
    - NOTE: requires 'encapsulation: ViewEncapsulation.None' in component definition
 */
.mat-step-header .mat-step-icon-state-done,
.mat-step-header .mat-step-icon-state-edit {
    background-color: green !important;
}

View Encapsulation on component:查看组件上的封装:

@Component({
    selector: 'a-stepper',
    templateUrl: './a-stepper.component.html',
    styleUrls: ['./a-stepper.component.css'],
    providers: [{
        provide: STEPPER_GLOBAL_OPTIONS, useValue: {showError: true}
    }],
    encapsulation: ViewEncapsulation.None
})
export class AStepperComponent implements OnInit {

Note: also my css is slightly different as only affects the background as I was putting a green tick rather than the edit with primary coloring.注意:我的 css 也略有不同,因为只影响背景,因为我打了一个绿色的勾,而不是用原色进行编辑。

You can override the iconset directly in your HTML.您可以直接在 HTML 中覆盖图标集。

<mat-horizontal-stepper>
    <!-- Icon overrides. -->
    <ng-template matStepperIcon="edit">
        <mat-icon>account_circle</mat-icon>
    </ng-template>
    <ng-template matStepperIcon="active">
        <mat-icon>account_circle</mat-icon>
    </ng-template>
    <ng-template matStepperIcon="done">
        <mat-icon>account_circle</mat-icon>
    </ng-template>
    <ng-template matStepperIcon="number">
        <mat-icon>account_circle</mat-icon>
    </ng-template>
</mat-horizontal-stepper>

It even works with font awesome:它甚至适用于很棒的字体:

<mat-horizontal-stepper>
    <!-- Icon overrides. -->
    <ng-template matStepperIcon="edit">
        <i class="fa fa-check-circle"></i>
    </ng-template>
    <ng-template matStepperIcon="active">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
    <ng-template matStepperIcon="done">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
    <ng-template matStepperIcon="number">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
</mat-horizontal-stepper>

For changing colors and other customizations please check https://stackoverflow.com/a/66428028/4184651如需更改颜色和其他自定义设置,请查看https://stackoverflow.com/a/66428028/4184651

.mat-step-header .mat-step-icon-selected, .mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit { background-color: #673ab7; .mat-step-header .mat-step-icon-selected, .mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit { 背景-颜色:#673ab7; color: #fff;颜色:#fff; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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