angular-material change checkbox color

前端 未结 17 1656
无人共我
无人共我 2020-12-16 11:22

I\'m using checkbox of angular-material2. Currently the default color of checkbox is coming as purple color.
Looks like they have changed default color of checkbox from

17条回答
  •  一整个雨季
    2020-12-16 11:51

    For me what has worked is the following:

    Check me!
    

    In the css (or in my case sass):

    .#{$wf__ns}checkbox {
      .mat-checkbox-ripple {
        .mat-ripple-element {
          background: $cool-blue !important;
        }
      }
    
      &.mat-checkbox-checked {
        .mat-checkbox-background {
          background: $cool-blue;
        }
        .mat-checkbox-ripple {
          .mat-ripple-element {
            background: $cool-blue !important;
          }
        }
      }
    }
    

    Explanation:

    The checked background color is changed to mat-checkbox-background within mat-checkbox-checked. IF you want to modify the background color when it is not checked just copy that part and copy it outside of mat-checkbox-checked.

    As for the ripple classes, it turns out that the material has an animation when you press the button. That class controls the color of the animation, if you don't change it it will remain the same (pink).

    If you do not change it by pressing the checkbox you will see a strange pink effect.

    The other answers do not work for me although I rely on the first to develop it.

    It may be from my version of angular that I leave below:

    Angular CLI: 8.3.25
    Node: 13.3.0
    Angular: 8.2.14
    

提交回复
热议问题