3

当该字段被禁用时,我试图从 mat-form-field 中删除边框,但我已经尝试了我可以在网上找到的所有选项,但似乎没有任何东西可以从 div 中删除边框

这是我的代码:

<div *ngIf="readOnly" class="medium-2 columns read-only-true">
  <mat-form-field appearance="outline" class="full-width">
    <mat-label>Employee ID</mat-label>
    <input [disabled]="readOnly" class="emp_id" required [(ngModel)]="form.id" matInput name="empID" placeholder="EMP #">
  </mat-form-field>
</div>

这是我到目前为止所尝试的:

第一种方法:

.read-only-true .mat-form-field-outline-start {
  border-color: white;
}

.read-only-true .mat-form-field-outline-gap {
  border-color: white;
}

.read-only-true .mat-form-field-outline-end {
  border-color: white;
}

第二种方法:

.read-only-true .mat-form-field-outline .mat-form-field-outline-start {
  border: white !important;
}

.read-only-true .mat-form-field-outline .mat-form-field-outline-end {
  border: white !important;
}

第三种方法:

::ng-deep .read-only-true .mat-form-field-appearance-outline .mat-form-field-outline .mat-form-field-outline-start {
  border: 1px solid white !important;
}

::ng-deep .read-only-true .mat-form-field-appearance-outline .mat-form-field-outline .mat-form-field-outline-end {
  border: 1px solid white; !important
}

::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
  color: white;
}

我非常感谢您对此的帮助,如果您希望我发布任何其他信息,请告诉我。

4

2 回答 2

1

在 mat-form-field div 上,替换appearance="outline"appearance="fill"

于 2021-04-01T09:40:35.157 回答
1

对于 CSS:

::ng-deep .mat-form-field-appearance-outline.mat-form-field-disabled .mat-form-field-outline {
opacity: 0;
}

HTML

<mat-form-field appearance="fill" class="full-width">
  <mat-label>Employee ID</mat-label>
  <input matInput type="text" value="value" [disabled]="true" class="emp_id">
</mat-form-field>
于 2021-04-01T10:12:02.980 回答