[英]React js how can i use css modules
Im currently using a component on two different page one is home page and one is product page and when I change the css of the product page the home page is also changing when I use the classes of the component how can I style the classes of this component for each css pages differently.我目前在两个不同的页面上使用一个组件,一个是主页,一个是产品页面,当我更改产品页面的 css 时,当我使用组件的类时,主页也会发生变化我如何设置这个类的样式每个 css 页面的组件不同。
You need to name your file with.modules.css..您需要将文件命名为.modules.css..
Then import styles from css/scss file in your component然后从组件中的 css/scss 文件导入 styles
"import styles from './.module.css';" “从'./.module.css'导入styles;” <--- Example
<--- 示例
Your can learn more on link below:您可以通过以下链接了解更多信息:
https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/ https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/
Create a separate css file for each page.为每个页面创建一个单独的 css 文件。
Then use然后使用
import './Product.css';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.