일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- Hermes Engine
- 테스트 Date
- Leetcode #javascript #알고리즘 #Algorithms #js
- 통신망분석
- 구름톤챌린지
- 구름톤 챌린지
- 최솟갑 구하기
- 프로그래머스
- 과제 진행하기
- nextjs-performance
- 호텔 대실
- mock date
- 구름톤
- Jest uuid syntax
- 연결 요소 제거하기
- 리액트네이티브
- JavaScript
- 헤르메스 엔진
- 자바스크립트
- 리액트네이티브 엔진
- mutationobserver
- 귤 고르기
- jest
- create-next-app
- ResizeObserver
- Google 애널리틱스
- 중첩 점
- 날짜 테스트
- 테이블 해시 함수
- nextjs
- Today
- Total
나만보는개발공부블로그
[Nextjs] Tailwind css 본문
Tailwind css 채택 이유?
이전에는 styled-components 를 사용하여서 프론트엔드 스타일링을 처리했는데 이번 nextjs doc를 살펴보면서 css-in-js에서는 server component에 지원되지 않는다고 하여서 nextjs에서 뭔가 밀어주고 있는듯하고 자체적인 config도 지원해주는 tailwind css를 새로운 사이드 프로젝트에 채택하기로 하였다.
redit에서도 tailwind css를 사용해서 빠른 스타일링 개발을 할 수 있다고 개발자들이 이야기 하고 있다.
https://www.reddit.com/r/nextjs/comments/14qhjmq/next_css_module_vs_tailwind/
From the nextjs community on Reddit
Explore this post and more from the nextjs community
www.reddit.com
Tailwind 적용 방법
현재 nextjs 폴더 안에서 다음과 같이 코드를 실행하면 패키지 설치와 tailwind관련 파일들을 생성해준다.
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
init 이후에 다음과 같은 파일 두개가 생성된다.
- tailwind.config.js
- postcss.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx,mdx}', // Note the addition of the `app` directory.
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
// Or if using `src` directory:
'./src/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
}
위와 같이 tailwind.config.js를 수정해주면 된다.
그리고 스타일 적용방법은 global.css 파일에 다음과 같이 맨 상단에 추가해준다.
tailwind 관련 지시어 - https://tailwindcss.com/docs/functions-and-directives#directives
@tailwind base;
@tailwind components;
@tailwind utilities;
그리고 root layout에 global.css를 import 해준다.
// These styles apply to every route in the application
import './globals.css'
그러면 className에 다음과 같이 tailwind의 class를 사용할수 있다.
export default function Page() {
return <h1 className="text-3xl font-bold underline">Hello, Next.js!</h1>
}
'Web Development > Front' 카테고리의 다른 글
Reflow와 Repaint 그리고 css관련 브라우저 최적화 (1) | 2023.11.23 |
---|---|
display:none VS visibility: hidden (1) | 2023.10.13 |
[React-query] Stale time vs Cache time (0) | 2023.09.17 |
[Nextjs] 프로젝트 구조 (Project Structure) (0) | 2023.09.16 |
[Nextjs] create-next-app (0) | 2023.09.12 |