垫中的字体真棒图标未按预期显示

问题描述

我正在开发一个有matInput的角度应用程序,并且试图在matInput的占位符中显示一个图标。我尝试使用的字体超赞图标是信息圈 我的代码

<mat-form-field>
    <input matInput
            class = "fas"
            placeholder= "&#xf05a;Default Value"
            [(ngModel)]="Value"
            style="font-family: Arial,'Font Awesome'">
</mat-form-field>

使用此代码,我可以看到一个图标,但是它没有按预期出现。

enter image description here

我已经交叉检查了图标代码及其正确性。我不知道怎么了。

解决方法

我不确定是否可行。我认为您需要在表单字段中添加一个mat-icon并将其标记为matPrefix:

<mat-form-field>
  <mat-label>A Label</mat-label>
  <input matInput placeholder="Placeholder">
  <mat-icon matPrefix>sentiment_very_satisfied</mat-icon>
</mat-form-field>

请参阅文档:material.angular.io/components/form-field/api

,

您可以这样做-

在您的HTML-

<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>
    <div class="input-wrapper">
       <mat-form-field>
       <input matInput
                class = "fas"                       
                >
      <label for="stuff" class="fa fa-info-circle"></label>
      </mat-form-field>
    </div>

在您的CSS-

.fa-info-circle{
  position: absolute;
  left: 3px;
  top: calc(50% - 0.5em); /* Keep icon in center of input,regardless of the input height */
}

::placeholder {
  text-align: center;
}
.input-wrapper{
  position: relative;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...