【发布时间】:2020-11-12 00:10:03
【问题描述】:
我需要使用::before 伪元素将Fontawesome 图标添加到输入字段。但是,该图标未显示,我无法弄清楚我做错了什么。 (我正在使用 Bootstrap 和 Fontawesome 5 Pro)。
.search-field-round::before {
content: '\f002';
font-family: 'Font Awesome 5 Pro';
font-weight: 900;
display: inline-block;
position: absolute;
top: 0;
left: -5px;
color: red;
}
<!-- Bootstrap CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<!-- FONT AWESOME CDN - Since I'm using a Pro version I do not wish to share my link here -->
<form class=" form-inline searchbar-form col-12 ">
<div class="col-10 search-field ">
<input type="search " class="form-control search-field-round " placeholder="¿Qué servicio buscas? ">
</div>
</form>
【问题讨论】:
-
我认为伪元素可以使用 fontawesome 的方式在版本 5 中发生了变化 - 请参阅 [link]stackoverflow.com/questions/47712987/… - 您现在必须启用它,因为它显然默认禁用。但不能使用正如@cloned 指出的那样,无论如何都在输入元素上。
标签: css