How Can I customize mat-form-field in disabled state

核能气质少年 提交于 2021-02-19 02:52:51

问题


I am trying to customize the angular material mat-form-field : I was able to customize the underline border using :

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

now I am trying to customize the underline border in the disabled state to be solid instead of the dashed line :

I tried this but it didn't work for underline :

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

 }

I want this to be gray solid in disabled state

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

回答1:


This Fixed it :

 ::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; 
    } 



回答2:


You need to target the following class:-

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

The css you will be looking to change is:-

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;

So you can either unset: all and start from fresh or update the background-size: 1px 100%; or whatever suits your needs




回答3:


This fixed it :

    ::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;
}



回答4:


You can try

::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);
    }


来源:https://stackoverflow.com/questions/54355907/how-can-i-customize-mat-form-field-in-disabled-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!