简体   繁体   中英

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.

You need to name your file with.modules.css..

Then import styles from css/scss file in your component

"import styles from './.module.css';" <--- Example

"btn" is example class in your css

Your can learn more on link below:

https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/

Create a separate css file for each page.

Then use

import './Product.css';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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