简体   繁体   English

Font-Awesome 图标未显示在我的 ReactJS 网站中

[英]Font-Awesome icon does not show in my ReactJS website

I'm trying to use a font next to my website's header in a react project I`m working on but it does not show.我正在尝试在我正在处理的 React 项目中使用我网站标题旁边的字体,但它没有显示。

I have imported the font-awesome package via yarn and imported the css of it in my index.js file but it does not show in my header.我已经通过 yarn 导入了font-awesome包,并在我的 index.js 文件中导入了它的 css,但它没有显示在我的标题中。

index.js:索引.js:

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
import "../node_modules/font-awesome/css/font-awesome.min.css";

ReactDOM.render(<App />, document.getElementById("root"));

Header Component:标题组件:

import React, { Component } from "react";

export default class Header extends Component {
  render() {
    return (
      <div>
        <div className="col-md-6 m-auto">
          <h1 className="text-center mb-3">
            <i className="fas fa-book-open"> </i>
            English Dictionary
          </h1>
        </div>
      </div>
    );
  }
}

Only the text of the header is shown.仅显示标题的文本。 I checked the browser for any errors and it did not show any, also when i inspect the page i see the element.我检查了浏览器是否有任何错误,但没有显示任何错误,当我检查页面时,我也看到了该元素。

<i className="fas fa-book-open"> </i>

I hope any of you can help me, thanks!希望大家帮帮我,谢谢!

You will need to follow these steps to use font-awesome with react :您需要按照以下步骤使用font-awesomereact

Install these dependencies:安装这些依赖项:

npm i @fortawesome/fontawesome-svg-core
npm i @fortawesome/free-solid-svg-icons
npm i @fortawesome/react-fontawesome

Make necessary imports where you need to use them:在需要使用它们的地方进行必要的导入:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faTimes } from '@fortawesome/free-solid-svg-icons'

Use in JSX:在 JSX 中使用:

<FontAwesomeIcon icon={faTimes} />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM