【问题标题】:Adding icon to the Angular Material input将图标添加到 Angular Material 输入
【发布时间】:2021-02-10 16:52:34
【问题描述】:

我正在尝试通过带有外观轮廓的角度材料输入来实现以下目标。

要在输入的右侧添加带有轮廓的图标,此图像也应位于材料选项卡内。到目前为止一切顺利,我的代码如下所示:

<div class="bigInputDiv">
<mat-form-field class="inputSEARCH" appearance="outline">
<mat-label>WWW</mat-label>
<input matInput type="text" formControlName='piradiNomeri'>
<img (click)="moqalaqeSearch('You clicked moqalaqe')" [ngClass]="(moqalaqeTAB.get('piradiNomeri').invalid && moqalaqeTAB.get('piradiNomeri').touched)?'svg error':'svg'" [src]="iconPath + 'addPersonSearch.svg'">
</mat-form-field>
</div>

还有风格

.bigInputDiv{
width: 100%;
max-width: 570px;
display: inline-flex;
width: 100%;
max-width: 700px;

.inputSEARCH {
  width: 100%;
  max-width: 565px;
  border-radius: 3px 0px 0px 3px!important;

  .svg {
    width: 48px;
    height: 47px;
    border-radius: 0px 4px 4px 0px;
    background-color: rgba(0,0,0,.12);
    cursor: pointer;
    padding: 10px;
    margin: 5px;
    position:absolute;
    margin-top: -20px;
    margin-left: -39px;
    &.error{
      background-color: red;
    }
    &:hover {
      background-color: black;
    }
  }
  :hover ~ .svg {
    background-color: black;
  }
  :focus ~ .svg {
    background-color: blue;
  }
  .ng-touched.ng-invalid ~ .svg {
    background-color: red;
  }
}
}

我认为问题出在这部分

  .svg {
    width: 48px;
    height: 47px;
    border-radius: 0px 4px 4px 0px;
    background-color: rgba(0,0,0,.12);
    cursor: pointer;
    padding: 10px;
    margin: 5px;
    position:absolute;
    margin-top: -20px;
    margin-left: -39px;
    &.error{
      background-color: red;
    }
    &:hover {
      background-color: black;
    }
  }

为了实现我的目标,我不得不使用大量带有边距和大小等的不可靠代码,因为我的输入看起来不稳定,我的意思是在不同的屏幕上输入看起来真的很糟糕并且超出了垫子输入字段。

【问题讨论】:

    标签: css input angular-material


    【解决方案1】:
    <mat-form-field appearance="outline">
        <mat-label>WWW</mat-label>
        <input matInput>
        <button type="button" mat-icon-button matSuffix>
            <mat-icon>search</mat-icon>
        </button>
    </mat-form-field>
    

    不需要额外的 css,只需在按钮上使用带有 matSuffix 指令的 mat-icon 按钮。

    【讨论】:

    • 可悲的是,你不能像我的图片那样把它的高度改成全宽,但至少在不同的屏幕上它不会弄乱
    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 2020-08-24
    • 2018-03-28
    • 1970-01-01
    • 2012-12-10
    • 2013-05-28
    • 1970-01-01
    • 2015-12-10
    相关资源
    最近更新 更多