Angular Material Overriding Default Style of SnackBar Component

前端 未结 6 1399
甜味超标
甜味超标 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 07:57

    To do this properly, you need to set the View Encapsulation to None on your component:

    @Component({
        templateUrl: './my.component.html' ,
        styleUrls: ['./my.component.css'], 
        encapsulation: ViewEncapsulation.None,
    })
    

    Then in your component css you can just do this:

    .mat-snack-bar-container {
       max-width: 800px;
    }
    

    From the official docs:

    View Encapsulation = None means that Angular does no view encapsulation. Angular adds the CSS to the global styles. The scoping rules, isolations, and protections discussed earlier don't apply. This is essentially the same as pasting the component's styles into the HTML.

提交回复
热议问题