Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material mat-expansion-panel-body style not being applied

I have the following css in my component's css file:

.mat-expansion-panel-body {
  padding: 0;
}

And, so I would expect to see this rule (even if overridden) to show up for the following dom element:

<div class="mat-expansion-panel-body">...</div>

But, all I see being applied in dev tools is:

.mat-expansion-panel-body {
  padding: 0 24px 16px;
}

I noticed that this element does not have the _ngcontent-c19 class that the other host elements do, and so I assume this is a case of view encapsulation.

However, after reading around with the deprecation of ::ng-deep and /deep/ and other encapsulation piercing constructs to be deprecated, what is a better solution to styling this element from within my component's css file?

like image 514
Ruklav-Nomad Avatar asked Nov 07 '18 17:11

Ruklav-Nomad


People also ask

How to disable expansion panel in Angular Material?

Disabling a panel Expansion panels can be disabled using the disabled attribute. A disabled expansion panel can't be toggled by the user, but can still be manipulated programmatically.

How do I keep my mat expansion panel from closing?

You can use [disabled]="isDisabled" on mat-expansion-panel .

How is angular material accordion used?

To use the Angular material accordion, we need to import MatExpansionModule into our custom module. It is up to you to add all material modules in a separate custom module or root module app. We are adding all material modules in a custom module, it containing only the material module.


2 Answers

I set up ::ng-deep in component css, it worked in my side.

::ng-deep .mat-expansion-panel-body{      padding: 0; } 
like image 85
Hien Nguyen Avatar answered Sep 20 '22 14:09

Hien Nguyen


One possible solution if you don't want to use ::ng-deep is to set the style in your styles.css file like so.

.mat-expansion-panel-body {
  padding: 0 !important;
}

This will remove the padding, but be careful as it will remove it from all of the mat-expansion-panel-body elements. You can bypass this by setting a specific class to your expansion panel and then doing something like this in styles.css

.my-special-class .mat-expansion-panel-body {
  padding: 0;
}

In this case you don't even need !important. Here is the example of this.

https://stackblitz.com/edit/angular-a6necw

like image 34
ibrcic Avatar answered Sep 22 '22 14:09

ibrcic