如何使用材料在同一行中制作图标和占位符? [英] How can i make icon and placeholder in same line using material?

查看:21
本文介绍了如何使用材料在同一行中制作图标和占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让图标和搜索字段在同一行.

<mat-form-field><mat-icon>搜索</mat-icon><input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter"></mat-form-field>

上面我添加了我的 html 代码..

演示

我写了很多 css 但我无法得到这个帮助我前进..

解决方案

不知道为什么其他答案如此复杂.只需将 matPrefixmatSuffixmat-button 一起使用(针对 Angular-material v7 进行了测试).

直接来自文档:

<input matInput type="text" placeholder="搜索"><button mat-button matPrefix mat-icon-button><mat-icon>搜索</mat-icon></mat-form-field><mat-form-field><input matInput type="text" placeholder="Clearable input"><button mat-button *ngIf="value" matSuffix mat-icon-button><mat-icon>关闭</mat-icon></mat-form-field>

I want to make icon and search field should be in same line .

<div class="example-header">
    <mat-form-field>
      <mat-icon>search</mat-icon>
      <input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
    </mat-form-field>
  </div>

Above i added my html code ..

demo

i wrote lot of css but i could't get this help me out to move forward..

解决方案

Not sure why other answers are so complicated. Just use matPrefix or matSuffix with mat-button (tested for Angular-material v7).

Straight from docs:

<mat-form-field>
  <input matInput type="text" placeholder="Search">
  <button mat-button matPrefix mat-icon-button>
    <mat-icon>search</mat-icon>
  </button>
</mat-form-field>


<mat-form-field>
  <input matInput type="text" placeholder="Clearable input">
  <button mat-button *ngIf="value" matSuffix mat-icon-button>
    <mat-icon>close</mat-icon>
  </button>
</mat-form-field>

这篇关于如何使用材料在同一行中制作图标和占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆