Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Angular Material mat-dialog-content styles

In angular dialogs you can add <mat-dialog-content>, but is there any way to style this?

I tried:

.mat-dialog-content {
    padding: 10px;
}

But that doesn't seem to work. Though, these two work fine:

.mat-dialog-container {
    padding: 0px !important;
}

.mat-dialog-title {
    color: white;
    background-color: #F48043;
    text-align: center;
    width: 100%;
    font-size: 20px;
    padding: 20px 0px !important;
}

Any idea how to access that <mat-dialog-content>'s styles?

like image 750
Frank Avatar asked Oct 16 '25 04:10

Frank


2 Answers

There is official guideline how to do it: https://material.angular.io/guide/customizing-component-styles E.g.

For example, to remove the padding from a dialog:

// Add this to your global stylesheet after your theme setup
.myapp-no-padding-dialog .mat-dialog-container {   
  padding: 0;
}

this.dialog.open(MyDialogComponent, {panelClass: 'myapp-no-padding-dialog'})

Since you are adding the styles to your global stylesheet, it is good practice to scope them appropriately. Try prefixing your selector with your app name or "custom". Also note that the mat-dialog-container's padding is added by default via a selector with specificity of 1. The customizing styles have a specificity of 2, so they will always take precedence.

like image 128
Stanislav Berkov Avatar answered Oct 17 '25 20:10

Stanislav Berkov


Using the CSS in style.css or any global CSS file.

You have to declare it as important, otherwise, the material style will override it.

.mat-dialog-content {
    padding: 10px !important;
}
like image 40
Prachi Avatar answered Oct 17 '25 19:10

Prachi