Fontawesome 图标在按钮元素内时隐藏
我刚刚将我的 fontawesome 升级到 6.0.0
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@fortawesome/free-regular-svg-icons": "^6.0.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/react-fontawesome": "^0.1.16",
我面临的问题是在带有父 div 的按钮内添加图标时。
这不会显示图标,
<div>
<button>
<FontAwesomeIcon
icon={faHeart}
size="2x"
className={`transform motion-safe:group-focus:scale-110 p-1.5 z-10`}
aria-hidden="true"
/>
</button>
</div>
如果我将其更改为简单的父 div,它会正确显示。
<div>
<div>
<FontAwesomeIcon
icon={faHeart}
size="2x"
className={`transform motion-safe:group-focus:scale-110 p-1.5 z-10`}
aria-hidden="true"
/>
</div>
</div>
有人知道为什么或如何让它与按钮一起工作吗?
I just upgraded my fontawesome to 6.0.0
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@fortawesome/free-regular-svg-icons": "^6.0.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/react-fontawesome": "^0.1.16",
The problem I am facing is when adding an Icon inside a button with a parent div.
This does not show the Icon
<div>
<button>
<FontAwesomeIcon
icon={faHeart}
size="2x"
className={`transform motion-safe:group-focus:scale-110 p-1.5 z-10`}
aria-hidden="true"
/>
</button>
</div>
If I change it to a simple parent div it shows up correctly.
<div>
<div>
<FontAwesomeIcon
icon={faHeart}
size="2x"
className={`transform motion-safe:group-focus:scale-110 p-1.5 z-10`}
aria-hidden="true"
/>
</div>
</div>
Does anyone one why or how to make it work with a button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请发布您的导入语句,我怀疑或周围的代码导致了您的问题 - 如果完整的代码如下所示,我就能使代码正常工作:
https://codesandbox.io/s/react-fontawesome-forked-moi0x5?file=/src/page/App.js
please post your import statements, I suspect that or surrounding code is causing your issue - I was able to get the code working if the complete code looks like below:
https://codesandbox.io/s/react-fontawesome-forked-moi0x5?file=/src/page/App.js
谢谢大家的回答,但我发现了问题。
我显然缺少一些配置,而最新版本则破坏了这一切。
这些需要添加到我的 _app.tsx (文档)
thank you all for your answers, but I found the issue.
I was apparently missing some config and that was breaking it all with the latest version.
these needed to be added in my _app.tsx (documentation)