Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to find CSS Selector for Material Design 2's md-dialog-container

Desperately trying to find a selector for md-dialog-container in angular 2's material design with no success.

I can make changes in f12 of chrome with no problem, but carrying out those changes with a valid selector in css is a problem. Researched /deep/ but it is now deprecated.

I have tried md-dialog-container {}, md-dialog-container.md-dialog-container{}, and md-dialog-container.md-dialog-container[role="dialog"] with no success.

Attached are images of me making these changes in f12 of chrome with no problem.

Normal padding of md-dialog-container

Removed padding of md-dialog-container in Chrome Tools

like image 468
John Stafford Avatar asked Feb 17 '17 20:02

John Stafford


People also ask

How do I change the default dialog container styles?

You can override the default dialog container styles by adding a css class in your global styles.css. For example: .custom-dialog-container .mat-dialog-container { /* add your styles */ } After that, you'll need to providies you css class as a panelClass parameter to your dialog: Read this official documentation for more information.

What is the Best CSS stylesheet for Material Design?

W3.CSS is the perfect stylesheet for designing applications with a "Material Design" look: The Cinque Terre (five lands) is a portion of the Italian Riviera.

What is Material Design in web design?

Material Design was designed by Google in 2014 and has later been adopted in many Google applications. Material Design uses elements that remind us of paper and ink. In addition the elements have realistic shadows and hover effects. W3.CSS is the perfect stylesheet for designing applications with a "Material Design" look:

How do I display multiple actions in a material dialog?

Use a simple dialog when displaying two actions. You have the option to use an alert when displaying two actions. When there are three or more actions with long text labels in a Material dialog, products may use iOS action sheets or bottom sheets. Stack actions if a text label is long.


3 Answers

Here's what worked for me:

  1. Set this on the dialog component itself:

encapsulation: ViewEncapsulation.None

  1. In the parent component set the panelClass on open e.g.
this.dialogRef = this.dialog.open(myDialogComponent, {
  panelClass: 'my-dialog'
 });
  1. In the css for the dialog component specifiy the panelClass e.g.
.my-dialog {

    .mat-dialog-container {
        padding: 0;
     }
}
like image 113
sarora Avatar answered Nov 15 '22 10:11

sarora


The issue you're running into is due to ViewEncapsulation. By default, Angular2 uses an emulated Shadow DOM which prevents styles from components affecting each other. You can opt out of ViewEncapsulation (not recommended) or you could use the /deep/ selector. According to Angular documentation in the link provided it is alright to use this selector using Angular's default emulated Shadow DOM.

From my understanding, Angular has its own CSS processor that should should make it alright for you to use these selectors for right now. I assume they're translated. If using these is truly not an option for you, you'll have to switch to ViewEncapsulation.None.

import {ViewEncapsulation} from '@angular/core'; // and any other imports

@Component({
  selector: 'my-selector',
  templateUrl: './my-selector.component.html',
  styleUrls: ['./my-selector.component.scss'],
  encapsulation: ViewEncapsulation.None
})
like image 43
Jesse Carter Avatar answered Nov 15 '22 10:11

Jesse Carter


For Angular and Material >6.x, I was able to use the ::ng-deep selector:

::ng-deep .mat-dialog-container {
  padding: 16px;
}
like image 28
Daniel Nitu Avatar answered Nov 15 '22 09:11

Daniel Nitu