Changing border color in mat-form-field

前端 未结 8 1478
猫巷女王i
猫巷女王i 2020-12-14 22:59

I am using angular material mat-form-field. I have a dark background, and therefore am trying to change the border of the form-field to white. But I am not able

相关标签:
8条回答
  • 2020-12-14 23:43

    For the newer outlined form fields, solved it this way:

    ::ng-deep {
         .mat-form-field-appearance-outline .mat-form-field-outline {
            color: white;
         }
         mat-form-field {
            .mat-hint, input, ::placeholder, .mat-form-field-label {
               color: white;
            }
         }
      }
    
    0 讨论(0)
  • 2020-12-14 23:44

    HTML

    <mat-form-field appearance="outline" style="margin: 0 20px;" class="border-red">
         <mat-label>Transaction Number</mat-label>
         <input matInput placeholder="Transaction number" [(ngModel)]="transactionNumber">
    </mat-form-field>
    

    SCSS

    $color-outline: red;
    
    mat-form-field {
       &.border-red {
          // to change border color
          ::ng-deep .mat-form-field-outline {
               color: $color-outline !important;
          }
          // to change label color
          ::ng-deep .mat-form-field-label {
               color: $color-outline !important;
          }
       }
    }
    

    this will work only if you give .border-red class to your mat-form-field.

    If you want to apply on all mat-form-field (remove border-red style rule)

    $color-outline: red;
    
    mat-form-field {
          // to change border color
          ::ng-deep .mat-form-field-outline {
               color: $color-outline !important;
          }
          // to change label color
          ::ng-deep .mat-form-field-label {
               color: $color-outline !important;
          }
    }
    
    0 讨论(0)
提交回复
热议问题