Angular Material Overriding Default Style of SnackBar Component

前端 未结 6 1400
甜味超标
甜味超标 2021-02-04 07:34

I am attempting to override the default max-width of the snackbar component in Angular Material.

The CSS applied by Angular Material is shown below:

.mat         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 08:07

    As of June 30, 2019, using Angular Material 8.0.1 with Angular 8.0.3, the following SCSS and typescript seems to work for overriding the color of the action button in an Angular Material snackbar *without using !important *:

    styles.scss (not the extremely long duration, which allowed me to inspect the styling before it disappeared):

    $snackBarTextColor: white;
    $snackBarBackgroundNormal: #087a51;
    $snackBarActionColor: lightgray;
    .snackBarInfo {
        background-color: $snackBarBackgroundNormal;
        color: $snackBarTextColor;
    
    
    }
    .mat-simple-snackbar > span {
        font-weight: bold;
    }
    .mat-simple-snackbar-action {
        .mat-button {
            .mat-button-wrapper {
                color: $snackBarActionColor;
            }
        }
    }
    

    app.module.ts:

    import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '@angular/material/snack-bar';
    providers: [
            {
                provide: MAT_SNACK_BAR_DEFAULT_OPTIONS,
                useValue: {
                    duration: 41000,
                    horizontalPosition: 'center',
                    verticalPosition: 'bottom',
                    panelClass: 'snackBarInfo'
                }
            }
        ]
    

提交回复
热议问题