6

I am trying to change the color of the angular material dialog using css var (), but instead of the color I need, the background becomes transparent.

Css style:

.custom-dialog >  mat-dialog-container {
  background: var(--background);
}

Open dialog function:

openDialogForCreateDirectory(): void {
    this.dialog.open(CreateDirectoryComponent, {
      width: '400px',
      panelClass: 'custom-dialog'
    });
  }
Nikita Kachan
  • 63
  • 1
  • 1
  • 3
  • Does this answer your question? [How to close a mat dialog without a backdrop on clicking outside?](https://stackoverflow.com/questions/57878327/how-to-close-a-mat-dialog-without-a-backdrop-on-clicking-outside) – Dane Brouwer Mar 17 '21 at 12:40

2 Answers2

4

You need to use ::ng-deep to force the style down to angular material components:

::ng-deep .custom-dialog > mat-dialog-container {
  background-color: var(--background);
}

See working example: https://stackblitz.com/angular/ebnbevodyrv

Alisson Reinaldo Silva
  • 10,009
  • 5
  • 65
  • 83
  • ng-deep & co are deprecated and should not be used. Instead define such overrides in a special file and import it to your global style. In this way it is possible to use for more than one dialog. – Thomas Renger Jan 06 '23 at 14:11
-1

To change anything in angular-material library UI, need to add css in styles.scss i.e. root level.

See here

Gourav Garg
  • 2,856
  • 11
  • 24