Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of matInput

How do I change matInput to a custom color. I want to change the placeholder and underline color.

I have read through most of the posts and could not find a solution to change the underline.

  <mat-form-field class="example-full-width">
    <input matInput placeholder="Favorite food" value="Sushi">
  </mat-form-field>

Stackblitz example

Image example

like image 611
Jarrod Avatar asked Jan 03 '19 20:01

Jarrod


People also ask

How do you change the color of matInput?

Using --> ::ng-deep. mat-form-field-ripple { /*change color of underline when focused*/ background-color: green ! important;; } works.

How do I change the color of my outline mat form field?

Go to Node_modules → @angular → material → prebuilt-themes → indigo-pink. css → Find mat-form-filed-appearance-outline, and then change your color.


1 Answers

You can use plain css

 ::ng-deep .mat-focused .mat-form-field-label {
  /*change color of label*/
  color: green !important;
 }

 ::ng-deep.mat-form-field-underline {
  /*change color of underline*/
  background-color: green !important;
} 

::ng-deep.mat-form-field-ripple {
 /*change color of underline when focused*/
 background-color: green !important;;
}

or create custom theme to apply on.Here is article,how to create custom themes

https://alligator.io/angular/angular-material-custom-theme/

like image 156
Nenad Radak Avatar answered Oct 15 '22 02:10

Nenad Radak