This project demonstrates how to use CSS Modules in a React application, particularly in the context of working with legacy stylesheets. It showcases how CSS Modules can help prevent style conflicts and improve the maintainability of your styles.
Check out the live demo: https://global-styles-demo-644f.vercel.app/
- A React component styled with CSS Modules
- Global styles that might exist in a legacy application
- How CSS Modules prevent the global styles from interfering with the component's styles
- CSS Modules: A CSS file in which all class names and animation names are scoped locally by default. Learn more
- Specificity: How browsers determine which CSS rule is applied when multiple rules could style an element. MDN explanation
- Working with Legacy Styles: Strategies for integrating modern CSS practices with existing codebases. CSS-Tricks article
src/components/Button/
: Contains a React button component and its CSS Modulesrc/global-styles.css
: Simulates legacy global stylessrc/App.tsx
: Main application file demonstrating the use of the button component alongside elements styled by global CSS
- Install dependencies:
yarn install
- Start the development server:
yarn dev
- Build for production:
yarn build
Feel free to explore the code and experiment with the styles to see how CSS Modules can help manage styling in complex applications!