简体   繁体   English

react/next.js 中的 * 选择器

[英]The * selector in react/next.js

I am currently working on my first website in react.我目前正在开发我的第一个响应网站。 In my main.module.css I have在我的main.module.css我有

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

Just typical css styling reset.只是典型的 css 样式重置。 But React returns the error:但是 React 返回错误:

Syntax error: Selector "*" is not pure (pure selectors must contain at least one local class or id)

Do you have any solution for that?你有什么解决办法吗? I want to keep this styling reset instead of adding those three lines to every element i have.我想保持这种样式重置,而不是将这三行添加到我拥有的每个元素中。

You should not have styling reset in module.css file.您不应该在 module.css 文件中重置样式。 Move this css reset to normal css file like index.css file.将此 css 重置为正常的 css 文件,如 index.css 文件。

Styling file with.module.css extensions are used to define the styling you can say local to a components.带有.module.css 扩展的样式文件用于定义您可以说是组件本地的样式。 It means that if you import a module.css file in two different components, both components will have same styles with different class names.这意味着如果您在两个不同的组件中导入 module.css 文件,两个组件将具有相同的 styles 和不同的 class 名称。 This one prevents overriding of styles.这可以防止覆盖 styles。

That would go into global styles, which can be done by simply adding:这会将 go 转换为全局 styles,只需添加:

require('./name-of-your-global-style.css');

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

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