본문 바로가기
프론트엔드/CSS 심화

CSS Modules

by 학습하는 청년 2024. 4. 18.

최종 수정 : 2024-04-18

CSS Modules

리액트 컴포넌트를 CSS로 개발하다보면 CSS 이름이 겹치는 문제가 발생할 수 있다. 이런 문제를 CSS Modules로 해결할 수 있다. 마치 자바스크립트 모듈을 사용하듯이 CSS 파일을 각각 독립적으로 사용할 수 있도록 해준다. 만약 같은 클래스 이름을 사용하더라도 CSS Moduels에서는 서로 다른 클래스 이름으로 인식한다. 

 

장점

컴포넌트 단위로 나누어서 스타일링 할 수 있어서 CSS 클래스 이름이 충돌하지 않는다.

필요하다면 Scss로 CSS Modules를 사용할 수 있다.

 

단점 및 한계

 


참고 자료

https://github.com/css-modules/css-modules

 

GitHub - css-modules/css-modules: Documentation about css-modules

Documentation about css-modules. Contribute to css-modules/css-modules development by creating an account on GitHub.

github.com

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

 

Adding a CSS Modules Stylesheet | Create React App

Note: this feature is available with react-scripts@2.0.0 and higher.

create-react-app.dev

https://nextjs.org/docs/pages/building-your-application/styling#adding-component-level-css

 

Building Your Application: Styling | Next.js

Learn the different ways you can style your Next.js application.

nextjs.org

 

'프론트엔드 > CSS 심화' 카테고리의 다른 글

Tailwind CSS  (0) 2024.04.18
CSS-in-JS  (0) 2024.04.18
Sass(SCSS)  (0) 2024.04.18
CSS 클래스 이름 설정 : BEM(Block Element Modifier)  (0) 2024.04.18
border: 0; 과 border: none;의 차이  (0) 2024.04.01

댓글