React.js未加载CSS文件。

huangapple go评论145阅读模式
英文:

react.js not load css file at all

问题

我构建了这个应用程序,但在模板的某个部分加载CSS时出现了问题。

这是我的CSS文件 styles.module.css

.my-page__title {
  font-weight: 300;
  font-size: 48px;
  margin-bottom: 15px;
}

.my-page__description {
  font-size: 14px;
  font-weight: 300;
  margin-bottom: 5px;
}

.my-page__wrapper {
  padding: 7px 10px;
  width: 100%;
  position: relative;
}

这是代码:

<Box className={styles['my-page__wrapper']}>
  <Box className={styles['my-page__title']}>
    Hello!
  </Box>
  <Typography className={styles['my-page__description']}>
    登录到您的账户
  </Typography>
</Box>

我的问题是类 my-page__wrappermy-page__title 成功加载,但类 my-page__description 无法识别它,文本格式不正确。我搜索了一下,但没有遇到类似的问题。有人知道我的错误在哪里吗?

英文:

I build the app and I get the problem with load the CSS in part of template.

This is my CSS file styles.module.css:

.my-page__title {
  font-weight: 300;
  font-size: 48px;
  margin-bottom: 15px;
}

.my-page__description {
  font-size: 14px;
  font-weight: 300;
  margin-bottom: 5px;
}

.my-page__wrapper {
  padding: 7px 10px;
  width: 100%;
  position: relative;
}

And here is the code:

&lt;Box className={styles[&#39;my-page__wrapper&#39;]}&gt;
  &lt;Box className={styles[&#39;my-page__title&#39;]}&gt;
    Hello!
  &lt;/Box&gt;
  &lt;Typography className={styles[&#39;my-page__description&#39;]}&gt;
    Login to your acc.
  &lt;/Typography&gt;
&lt;/Box&gt;

My problem is the class &quot;my-page__wrapper&quot; and &quot;my-page__title&quot; was loaded successfully, but on the class &quot;my-page__description&quot; it does not recognize it, and it does not format the text properly.
I searched around but didn't come across a similar problem.
Does anyone know where my mistake is?

答案1

得分: 1

Mui的Typography组件不识别className属性。相反,你应该像这样将你的类传递为一个对象:

<Typography classes={{
    root: styles['my-page__description']
}}>
    登录到你的账户
</Typography>

你可以在文档中了解更多关于覆盖和扩展 Mui 类名的信息。

英文:

Mui's Typography component does not recognize the className prop. Instead you should pass your classes as an object like this:

&lt;Typography classes={{
    root: styles[&#39;my-page__description&#39;]
}}&gt;
    Login to your acc.
&lt;/Typography&gt;

You can read more about overriding and extending mui class names on the docs

huangapple
  • 本文由 发表于 2023年3月10日 00:19:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定