简体   繁体   English

CSS不适用于组件

[英]CSS doesn't apply to a component

I have a react component that is wrapped up in div: 我有一个包装在div中的react组件:

AccountLogin.jsx: AccountLogin.jsx:

import './AccountLogin.css';
export default observer(() => (
  <div className="content">
    Something here
  </div>
));

AccountLogin.css: AccountLogin.css:

.content {
  color: blue;
  background-color: blue;
  margin: 500px;
}

But the css doesn't apply to my rendered component AccountLogin. 但是,css不适用于我呈现的组件AccountLogin。

Any ideas why that could happen? 有什么想法为什么会发生吗?

Looking at rfx-stack source , I can see that files suffixed with .global.css are imported in global scope where as others are imported as css-modules . 查看rfx-stack源 ,我可以看到以.global.css为后缀的文件是在全局范围内导入的,而其他文件则是作为css-modules导入的。

So you can either rename your file to AccountLogin.global.css or use the imported class name: 因此,您可以将文件重命名为AccountLogin.global.css或使用导入的类名:

import styles from './AccountLogin.css';

Within component: 
<div className={styles.content}>...</div>

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

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