如何将字体真棒图标插入文本输入?

Che*_*ylG 6 html css css3 webfonts font-awesome

如何在输入字段中插入日历Web字体图标?

在此输入图像描述

HTML:

<input class="start_date" type="text">
Run Code Online (Sandbox Code Playgroud)

CSS:

.start_date:before {
  font-family: "FontAwesome";
  content: "\f073";
}
Run Code Online (Sandbox Code Playgroud)

Sti*_*ers 12

<input>是一个自动关闭的标签,你不能有任何:before:after伪元素.你可以把它包装成一个<label><span>如此,重视它.

.start_date:before {
  font-family: "FontAwesome";
  content: "\f073";
}

.start_date:before,
.start_date input {
  vertical-align: middle;
}
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<label class="start_date">
  <input type="text" placeholder="Date">
</label>
Run Code Online (Sandbox Code Playgroud)

以下是将图标放在输入字段内的示例.

.start_date {
  position: relative;
}

.start_date:before {
  font-family: "FontAwesome";
  font-size: 14px;
  content: "\f073";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.start_date input {
  text-indent: 18px;
}
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<label class="start_date">
  <input type="text" placeholder="Date" />
</label>
Run Code Online (Sandbox Code Playgroud)