Change default background color of md-slider of Angular Material

后端 未结 7 635
野的像风
野的像风 2021-02-04 20:06

I am using md-slider of Angular Material version 2.0.0-beta.8

I have selected the indigo-pink theme and imported it in

7条回答
  •  余生分开走
    2021-02-04 21:04

    You can use ::ng-deep override any css class from the prebuilt stylesheet.

    To apply the custom change for whole app, add the custom class to root component's stylesheet, usually styles.css.

    css to customize md-slide-toggle:

    /* CSS to change Default/'Accent' color */
    
    ::ng-deep .mat-slide-toggle.mat-checked:not(.mat-disabled) .mat-slide-toggle-thumb {
        background-color: blue; /*replace with your color*/
    }
    
    ::ng-deep .mat-slide-toggle.mat-checked:not(.mat-disabled) .mat-slide-toggle-bar {
        background-color: skyblue;  /*replace with your color*/
    }
    
    /* CSS to change 'Primary' color */
    
    ::ng-deep .mat-slide-toggle.mat-primary.mat-checked:not(.mat-disabled) .mat-slide-toggle-thumb {
        background-color: green;
    }
    
    ::ng-deep .mat-slide-toggle.mat-primary.mat-checked:not(.mat-disabled) .mat-slide-toggle-bar {
        background-color: #ff99ff;
    }
    
    /* CSS to change 'Warn' color */
    
    ::ng-deep .mat-slide-toggle.mat-warn.mat-checked:not(.mat-disabled) .mat-slide-toggle-thumb {
        background-color: red;
    }
    
    ::ng-deep .mat-slide-toggle.mat-warn.mat-checked:not(.mat-disabled) .mat-slide-toggle-bar {
        background-color: #ffe066;
    }
    

    Plunker example

提交回复
热议问题