简体   繁体   English

如何在材质 UI 中使用外部 scss 或 css 文件? (反应)

[英]How to use external scss or css file with material UI? (react)

I am facing problem with external css files on my react project.我在我的反应项目中遇到了外部 css 文件的问题。 I am using material UI components.我正在使用材质 UI 组件。 In the react components folder I created css file for each components but they are not loading when i hard reload the site.在反应组件文件夹中,我为每个组件创建了 css 文件,但是当我硬重新加载站点时它们没有加载。

I wanted to use external css rather than styled components or material ui style syntax.我想使用外部 css 而不是样式组件或材质 ui 样式语法。

Just import the css / scss file in your component and make sure you've added the classes for the elements.只需在您的组件中导入 css / scss 文件并确保您已添加元素的类。

If you are looking a more generic option you can import your style.css file in your main App.jsx (if you call it "App.jsx") file.如果您正在寻找更通用的选项,您可以将 style.css 文件导入主 App.jsx(如果您称其为“App.jsx”)文件。 Then you just use the className and will have access to your css.然后您只需使用className即可访问您的 css。

App.jsx file应用程序.jsx 文件

import './style.css'; // Your path to your style.css    

function App() {
  return (
    <div>React app</div>
  );
}

export default App;

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

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