5

我正在尝试自定义角度材料 mat-form-field :我能够使用以下方式自定义下划线边框:

::ng-deep.mat-form-field-ripple {
  background-color: yellow;
}

现在我正在尝试将禁用状态下的下划线边框自定义为实线而不是虚线:

我试过这个,但它不适用于下划线:

::ng-deep.mat-form-field-disabled
 {

 }

在此处输入图像描述

我希望它在禁用状态下是灰色的

 <mat-form-field>
    <input matInput placeholder="Input" [disabled]='true'>
  </mat-form-field>
4

5 回答 5

8

这修复了它:

 ::ng-deep.mat-form-field-disabled .mat-form-field-underline 
    { 
    background-image: linear-gradient( to right, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.42) 33%, #c2c7cc 0 ) !important; 
    background-size: 1px 100% !important;
     background-repeat: repeat-x !important; 
    } 
于 2019-04-30T00:37:06.793 回答
1

您需要针对以下课程:-

.mat-form-field-disabled .mat-form-field-underline

您将要更改的 CSS 是:-

background-image: linear-gradient(to right,rgba(0,0,0,1) 0,rgba(0,0,0,.42) 33%,transparent 0);
background-size: 4px 100%;
background-repeat: repeat-x;

因此,您可以unset: all从新开始,也可以更新background-size: 1px 100%;或满足您的需求

于 2019-01-24T22:13:28.117 回答
1

你可以试试

::ng-deep .mat-form-field-disabled {
   .mat-input-element {
        color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-label {
        color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-underline {
         color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-ripple {
         color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-required-marker {
         color: rgba(0, 0, 0, 0.14);
    }
于 2021-01-19T08:26:06.973 回答
0

您不需要背景图像中的线性渐变。这对我有用:

::ng-deep .mat-form-field-disabled .mat-form-field-underline {
  background-color: #949494 !important;
  background-size: 1px 100% !important;
  background-repeat: repeat-x !important;
}
于 2022-02-11T15:21:16.640 回答
0

这修复了它:

    ::ng-deep.mat-form-field-disabled .mat-form-field-underline {
    background-image: linear-gradient(
    to right,
    rgba(0, 0, 0, 1) 0,
    rgba(0, 0, 0, 0.42) 33%,
    #c2c7cc 0
  ) !important;
  background-size: 1px 100% !important;
  background-repeat: repeat-x !important;
}
于 2019-01-25T00:43:43.737 回答