Style the Angular Material Slider so that it is thicker / taller

后端 未结 3 1378
忘了有多久
忘了有多久 2021-02-20 12:02

I\'m having problems finding the magic sauce here.. It doesn\'t look like the API supports it, so I guess I\'m looking for some CSS to make the slider bigger.

3条回答
  •  逝去的感伤
    2021-02-20 12:33

    You can try to add this CSS to global style:

    .mat-slider.mat-slider-horizontal .mat-slider-wrapper {
      top: 18px;
    }
    .mat-slider.mat-slider-horizontal .mat-slider-track-wrapper {
      height: 12px;
      border-radius: 10px
    }
    .mat-slider.mat-slider-horizontal .mat-slider-track-background,
    .mat-slider.mat-slider-horizontal .mat-slider-track-fill {
      height: 100%;
    }
    .mat-slider.mat-slider-horizontal .mat-slider-track-fill {
      background-color: blue;
    }
    .mat-accent .mat-slider-thumb {
      height: 30px;
      width: 30px;
      background-color: white;
      border: solid 2px gray;
      bottom: -20px;
      right: -20px;
    }
    .mat-slider-min-value:not(.mat-slider-thumb-label-showing) .mat-slider-thumb {
      background-color: white;
    }
    

    STACKBLITZ

    if you need to have these styles in any component's CSS file with default encapsulation, just add ::ng-deep before each CSS rule (but be aware of its long going deprecation, so check it with each new versions of Angular):

    ::ng-deep .mat-slider.mat-slider-horizontal .mat-slider-wrapper {
      top: 18px;
    }
    ::ng-deep .mat-slider.mat-slider-horizontal .mat-slider-track-wrapper {
      height: 12px;
      border-radius: 10px
    }
    ...
    

    if using SASS, just wrap your code with ::ng-deep

    ::ng-deep {
      .mat-slider.mat-slider-horizontal .mat-slider-wrapper {
        top: 18px;
      }
      .mat-slider.mat-slider-horizontal .mat-slider-track-wrapper {
        height: 12px;
        border-radius: 10px
      }
      ...
    }
    

    Please note, that this way your CSS will affect global CSS scope.

提交回复
热议问题