【问题标题】:Angular Material: Cross-browser search input with clear buttonAngular Material:带有清除按钮的跨浏览器搜索输入
【发布时间】:2019-09-20 20:41:48
【问题描述】:

我正在寻找一个类似于 HTML5 的带有清除按钮的跨浏览器搜索控件

<input type="search">

由 Chrome 渲染:

我使用this code 获得的最相关结果,我使用了“无外观”的标准样本,因为我不需要应用下划线和其他一些样式:

<mat-form-field class="example-form-field" appearance="none">
  <input matInput type="text" placeholder="Clearable input" [(ngModel)]="value">
  <button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
    <mat-icon>close</mat-icon>
  </button>
</mat-form-field>

但按钮在不同情况下可能会上下浮动:

UPD。这不是对图书馆、书籍或教程的搜索:D

【问题讨论】:

    标签: javascript css angular typescript angular-material


    【解决方案1】:

    喜欢这里对细节的关注...我会把这个 CSS 放在你的 input-clearable-example.css 中:

    input.mat-input-element{margin-top:0; padding-bottom:7px;}
    

    或 ng-deep(以防它不起作用......虽然它应该)

    ::ng-deep input.mat-input-element{margin-top:0; padding-bottom:7px;}
    

    工作stackblitz here

    【讨论】:

    • 感谢您的回答。不幸的是,这两个选项都不起作用:(我们需要更新输入或按钮的样式吗?
    • @BorisSokolov,我已经用我看到的结果更新了这个问题......你能打开分叉的 stackblitz 链接(在答案中),让我知道它是否适合你吗?
    • 啊...它在 FireFox 中看起来有点不同 :(
    • 在 Chrome 中看起来还不错
    • input.mat-input-element{ margin-top: 0; padding-bottom: 15px;} 可以在 Firefox 中使用...快到 2020 年了,浏览器仍然不是“完全标准的”:(
    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 2019-04-28
    • 2020-07-29
    • 2012-05-18
    • 1970-01-01
    • 2017-08-11
    • 2015-03-22
    • 2015-10-29
    相关资源
    最近更新 更多