我在Stackoverflow上跟踪这个问题.

Textbox Highlighting

Expected Search Box

我希望对具有此代码的搜索框进行相同的突出显示.

<mat-form-field  class="custom-form-field" appearance="outline" style="padding-top: 5px;padding-bottom: 0px; line-height: 0px;">
    <input style="padding-top: 0px; padding-bottom: 0px;" matInput type="text" id="onSearch" (keyup)="keyUp($event)">
    <mat-icon matPrefix class="centered-icon">search</mat-icon>
</mat-form-field>

它的CSS码如下所示.

.custom-form-field .mat-form-field-outline-thick,
.custom-form-field
.mat-form-field-appearance-outline.mat-focused
.mat-form-field-outline-thick {
    border-color: #ced4da !important;
    border-width: 0px !important;

    color: #ced4da !important;
    opacity: 1 !important;
}
.custom-form-field .mat-input-element {
    caret-color: #ced4da !important;
    color: #575e64;
}
.custom-form-field .mat-form-field-infix {
    border-top: 0px !important;
    padding: 0.9em 0 0.6em 0 !important;
}
.custom-form-field .mat-form-field-prefix {
    top: -1px !important;
    color: #575e64;
}
.custom-form-field .mat-form-field-outline-start,
.custom-form-field .mat-form-field-outline-end,
.custom-form-field .mat-form-field-outline-gap {
    border-width: 1px !important;
}

蓝色突出显示不会对输入文本框应用任何样式.但是,如果我将输入文本框转换为mat-form-field,突出显示将与当前代码一起消失.

至少从Angular Material表单域转换到文本框对我来说也是可以的…

推荐答案

您可以只使用outline的css来满足此要求.我们可以用outline: #bfdeff solid 2px !important;

CSS

.custom-form-field .mat-form-field-outline-thick,
.custom-form-field
  .mat-form-field-appearance-outline.mat-focused
  .mat-form-field-outline-thick {
  border-color: #ced4da !important;
  border-width: 0px !important;

  color: #ced4da !important;
  opacity: 1 !important;
}
.mat-form-field-appearance-outline.mat-focused .mat-form-field-outline-thick {
  outline: #bfdeff solid 2px !important;
  border-radius: 5px;
}
.custom-form-field .mat-input-element {
  caret-color: #ced4da !important;
  color: #575e64;
}
.custom-form-field .mat-form-field-infix {
  border-top: 0px !important;
  padding: 0.9em 0 0.6em 0 !important;
}
.custom-form-field .mat-form-field-prefix {
  top: -1px !important;
  color: #575e64;
}
.custom-form-field .mat-form-field-outline-start,
.custom-form-field .mat-form-field-outline-end,
.custom-form-field .mat-form-field-outline-gap {
  border-width: 1px !important;
}

stackblitz->;cd test->;npm i->;npm run start

Css相关问答推荐

Safari CSS扫描动画效果不起作用

在NextJS/Reaction应用程序中显示更新问题

如何防止css边框缩小div?

material 设计--Bootstrap输入域问题

Css模糊了Chrome中的框边框

覆盖现有像素的混合

React MUI 从 CSS 伪元素中删除内容

如何阻止 Mud Blazor MudTable 列扩展以适合文本

SASS 中的计算表达式

做一个像CodeSandbox的console那样的可拖拽的split panel

Flex & space-around 与内容相交

如何在特定元素之前 Select 每个元素

如何在 CSS 中更改 ::marker SVG colored颜色 ?

nth-child 在一个页面上工作,但不在另一个页面上

CSS nth-child 表示大于和小于

为什么我们将