css - React Fontawesome CSS 伪元素不在 div 内呈现,但在 Codepen 中工作
问题描述
我正在运行一个 React 应用程序,我需要在这个 Codepen中的选择表单字段内呈现一个 FontAwesome 图标
为了实现这一点,我使用 CSS Pseudo Elements, :after 具体定义为here
不幸的是,这在这个 CodePen中运行良好,但它不会在我的应用程序的 div 中呈现。我得到一个框,显示 FontAwesome 图标未呈现,实际图标出现在选择输入之后。请参阅下图了解它的外观。
CSS
.selectdiv {
position: relative;
}
.selectdiv:after {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f107";
color: rgb(75,173,233);
right: 0rem;
top: 0.3rem;
height: 2rem;
padding: 0rem 0rem 0rem 0rem;
position: absolute;
pointer-events: none;
}
/* IE11 hide native button*/
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgb(75,173,233);
background-color: #ffffff;
background-image: none;
-ms-word-break: normal;
word-break: normal;
}
索引.html
<!-- FontAwesome Pseudo Elements Config -->
<script src="https://use.fontawesome.com/releases/v5.12.0/js/all.js" data-search-pseudo-elements></script>
<script>
window.FontAwesomeConfig = {
searchPseudoElements: true
}
</script>
解决方案
在这里找到了答案
我遵循“旧方式”。
我将此行添加到 index.html
<link href="https://use.fontawesome.com/releases/v5.12.0/css/all.css" rel="stylesheet">
我的 CSS 现在看起来像这样
.selectdiv {
position: relative;
}
.selectdiv::after {
font-family: "Font Awesome\ 5 Free";
content: "\f107";
font-weight: 600;
color: rgb(75,173,233);
right: 0rem;
top: 0.3rem;
height: 2rem;
padding: 0.2rem 0rem 0rem 0rem;
position: absolute;
pointer-events: none;
}
/* IE11 hide native button*/
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgb(75,173,233);
background-color: #ffffff;
background-image: none;
-ms-word-break: normal;
word-break: normal;
}
推荐阅读
- windows - CreateEnvironmentBlock 可以给出一个空列表,它会导致这次崩溃吗?
- vsto - 哪个 RibbonType 将在 Outlook (2013) VSTO 加载项中显示已发送消息的自定义功能区?
- powerbi - 在 M 查询与查找 DAX 的字符串函数中查找字符的位置
- sql-server - MS Access 中通过 ODBC 连接 MS SQL 表的查询非常慢
- python - 无法在python中使用变量作为全局变量
- java - 从方法中获取返回值以在for循环中使用
- javascript - 为什么 XMLDocument.evaluate 在此 WMS GetCapabilities 文档中找不到节点
- c# - 当我更改 C# COM dll 的签名时,为什么我必须从 x86 到 msil 再回到 x86
- reactjs - 如何在反应导航中将标题移动到stackNavigator的底部?
- kubernetes - How to restart Kubernetes pod when a secret is updated in Hashicorp Vault?