在 React 应用程序中导入 CSS

use*_*265 5 reactjs

创建 React 应用程序文档中,它说 App.css 已导入 App.js 中。还有一种方法可以从组件加载编译后的 css 文件吗?

// 我的视图组件

import styles from '../../App.css';
Run Code Online (Sandbox Code Playgroud)

Joh*_*uel 5

您只需在组件中导入如下所示的 css 文件即可

导入'./header.css';

Imagine your header.css file looks like 

.header {
    background-color:  rgb(49, 118, 197);
    height:100px;
    border:10px solid red;
}

To use the style, you can use the class like ,

<div className="header">Hello World</div>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助 :)