Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite angular 2 material styles?

I have this select in angular material:

enter image description here

Its code :

<md-select placeholder="Descuentos y convenios" [(ngModel)]="passenger.discount">         <md-option [value]="null" [disabled]="true">             Descuentos         </md-option>         <md-option *ngFor="let option of discounts" [value]="option">             {{ option }}         </md-option>         <md-option [value]="null" [disabled]="true">             Convenios         </md-option>         <md-option *ngFor="let option of agreements" [value]="option">             {{ option }}         </md-option> </md-select> 

And I would like to have this styles in it:

enter image description here

I tried to put some classes over md-select and md-option, but not worked. I would like to have maybe just an example of how to put the background color or the border and that would give me an idea.

Thank you in advance

like image 206
Kimy BF Avatar asked Apr 28 '17 23:04

Kimy BF


People also ask

How do I override angular materials class?

Our solution to ViewEncapsulation was to override very specific css using highly specific css selectors in 1) global css or 2) creating separate style files for certain views / styles / elements, importing into every component required (e.g. styleUrls: [material-table-override.

How do you override styles in material UI?

If you want to override a component's styles using custom classes, you can use the className prop, available on each component.

Is ng-deep deprecated?

Both APIs ::ng-deep and /deep/ are deprecated and will eventually be removed in the future.


1 Answers

I think classes should work, but you may need to use /deep/ because of the view encapsulation.

Try this:

/deep/ md-select.your-class {   background-color: blue; } 

You can also play with theming.

like image 90
André Avatar answered Sep 16 '22 15:09

André