Angular Material 15 – 如何更改 mat-mdc-form-field 轮廓的边框颜色

huangapple go评论43阅读模式
英文:

Angular Material 15 - How to change border color of a mat-mdc-form-field outline

问题

<p>
  <mat-form-field appearance="outline">
    <mat-label>轮廓表单字段</mat-label>
    <input matInput placeholder="占位符">
    <mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
    <mat-hint>提示</mat-hint>
  </mat-form-field>
</p>
mat-form-field{
  background-color: #f3f6f9; // 成功
  border:2px solid red; // 这会添加另一个边框,所以不能解决问题
}
英文:

How do i change mat-form-field apearance outline underline color in Angular Material **Version 15 **

this post stackoverflow were great helpful but i could not change border color with this because we have not $border propertie on mat.define-typography-level( ) material.angular.io

<p>
  <mat-form-field appearance="outline">
    <mat-label>Outline form field</mat-label>
    <input matInput placeholder="Placeholder">
    <mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
    <mat-hint>Hint</mat-hint>
  </mat-form-field>
</p>

I tried to overide border without success

mat-form-field{
  background-color: #f3f6f9; // success
  border:2px solid red; // it's add another border so not resolve  
}

答案1

得分: 1

我是你的中文翻译:

// 顶部和底部边框如果标签在内部
::ng-deep.mdc-notched-outline__notch {
  border-top: 2px solid red !important;
  border-bottom: 2px solid red !important;
}

// 顶部和底部边框如果标签是凹陷的
::ng-deep.mdc-notched-outline--notched {
    ::ng-deep.mdc-notched-outline__notch {
       border-top: none !important;
       border-bottom: 2px solid red !important;
    }
}

// 带有边缘的左边框
::ng-deep.mdc-notched-outline__leading {
  border: 2px solid red !important;
  border-right: none !important;
}

// 带有边缘的右边框
::ng-deep.mdc-notched-outline__trailing {
  border: 2px solid red !important;
  border-left: none !important;
}
英文:

I have achieved it this way. So it works, but maybe there is an easier way. I found the neccessary CSS-Classes on the offical MDC Docs

//Top bottom border, if label is inside 
::ng-deep.mdc-notched-outline__notch {
  border-top: 2px solid red !important;
  border-bottom: 2px solid red !important;
}

//Top bottom border, if label is notched
::ng-deep.mdc-notched-outline--notched {
    ::ng-deep.mdc-notched-outline__notch {
       border-top: none !important;
       border-bottom: 2px solid red !important;
    }
}
//Left border with edges
::ng-deep.mdc-notched-outline__leading {
  border: 2px solid red !important;
  border-right: none !important;
}
//Right border with edges
::ng-deep.mdc-notched-outline__trailing {
  border: 2px solid red !important;
  border-left: none !important;
}

答案2

得分: 0

你可能正在寻找CSS的outline-color属性。

例如:

.hide-outline-color:focus-visible {
  outline-color: transparent;
}
英文:

You might be looking for css outline-color property.

EX.

<input class="hide-outline-color" />

then in your css

.hide-outline-color:focus-visible {
  outline-color: transparent;
}

huangapple
  • 本文由 发表于 2023年2月18日 00:13:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定