我try 了所有我能找到的方法来更改垫子输入中的笔划 colored颜色 ,但 colored颜色 仍然是紫色.字体的 colored颜色 完全改变了,但是边界线却没有.我能用这个做什么?

以下是html:

<div class="login-page">
    <h2>Login</h2>
    <div id="form">
        <form [formGroup]="loginForm">
            <div class="justify-content-center">
                <mat-form-field class="mffield" appearance="outline">
                    <mat-label>Username</mat-label>
                    <input matInput formControlName="username">
                </mat-form-field>
            </div>
            
            <div class="justify-content-center">
                <mat-form-field class="mffield" appearance="outline">
                    <mat-label>Password</mat-label>
                    <input type="password" matInput formControlName="password">
                </mat-form-field>
            </div>

            <div id="controls" class="row">
                <button style="width: 20%;" [disabled]="loginForm.invalid" (click)="submit()" mat-flat-button color="primary">
                    Login
                </button>
            </div>
        </form>
    </div>
</div>

以下是css:

...
  
.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__trailing {
  border-color: red !important;
}

.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__trailing {
  border-color: red !important;
}

.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__trailing {
  border-color: red !important;
}

我试过这个代码

.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled) .mdc-notched-outline__trailing {
  border-color: red !important;
}

.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled).mdc-text-field--focused .mdc-notched-outline__trailing {
  border-color: red !important;
}

.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__leading,
.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__notch,
.mdc-text-field--outlined:not(.mdc-text-field--disabled):not(.mdc-text-field--focused):hover .mdc-notched-outline .mdc-notched-outline__trailing {
  border-color: red !important;
}

大概是这样的:

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

但这对我不起作用.

推荐答案

Angular Material在css变量上做得很好. 在这种情况下,您可能需要--mdc-outlined-text-field-outline-color,这是文本字段的轮廓 colored颜色 的来源.

在下面的示例中,使用style property binding syntax将轮廓 colored颜色 设置为红色.

<mat-form-field class="mffield" appearance="outline"
  [style.--mdc-outlined-text-field-outline-color]="'red'">
  <mat-label>Username</mat-label>
  <input matInput formControlName="username">
</mat-form-field>

你也可以在css中这样做. 我注意到你的表单字段上有一个名为mffield的类. 您可以简单地在该类的规则中设置属性值.

.mffield {
  --mdc-outlined-text-field-outline-color: red;
}

Html相关问答推荐

卡片上方的文本

Flexbox嵌套div溢出

试图让三个Divs与下面的另外三个对齐

当使用浮动标签和大小时,如何在 Select 组件中有更多可见选项?

在 bootstrap 中的弹性项之间添加连接行

如何防止第二列中的内容影响第一列中内容的位置?

标签数据的XPath?

如何在html和css中创建动态调整大小的表元素

是否可以部分列出一个HTML有序列表

如何使用CSS在NSAttributedString中为HTML文本中的图像制作覆盖图

为什么前端框架可以创建自定义属性,而我却被期望在挖掘之前添加数据

使用响应迅速的网格系统,将两列保持在同一行,同时允许更多列用于更大的屏幕

获取标准的Python脚本,以便使用FASK对网站进行Flask

在TWebLabel标题中设置换行符/换行符的方法?

div居中碰撞问题

如何在悬停时更改同级元素 CSS

:after 伪元素没有出现,即使它有 content 属性

在 flexbox 中使用 spacer 是否有效

如何让一个 div 元素粘在另一个元素上?

在随机图像下对齐文本