๐ŸŽจ ํ”„๋ก ํŠธ์—”๋“œ ๐ŸŒฑ ์ž…๋ฌธ

Tailwind CSS ์‹ค์ „

Utility-First CSS๋กœ ๋น ๋ฅด๊ฒŒ UI ๊ตฌ์ถ•ํ•˜๊ธฐ

โฑ๏ธ 6์‹œ๊ฐ„ ๐Ÿ‘๏ธ 25 ์กฐํšŒ โญ ์ถ”์ฒœ ๊ฐ•์ขŒ
๐Ÿ“– ๊ฐ•์ขŒ ๋‚ด์šฉ
# Tailwind CSS ์‹ค์ „ ๊ฐ€์ด๋“œ

## ํ•™์Šต ๋ชฉํ‘œ
์œ ํ‹ธ๋ฆฌํ‹ฐ ์šฐ์„  CSS ํ”„๋ ˆ์ž„์›Œํฌ์ธ Tailwind CSS๋ฅผ ๋งˆ์Šคํ„ฐํ•ฉ๋‹ˆ๋‹ค.

## 1. Tailwind๋ž€?
์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค๋ฅผ ์กฐํ•ฉํ•ด ๋””์ž์ธํ•˜๋Š” CSS ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค.
- ๋น ๋ฅธ ๊ฐœ๋ฐœ ์†๋„
- ์ผ๊ด€๋œ ๋””์ž์ธ ์‹œ์Šคํ…œ
- ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ์šฉ์ด
- ์ž‘์€ ํ”„๋กœ๋•์…˜ ๋นŒ๋“œ ํฌ๊ธฐ

## 2. ์„ค์น˜
npm install -D tailwindcss
npx tailwindcss init

# tailwind.config.js
module.exports = {
content: ["./src/**/*.{html,js,jsx,ts,tsx}"],
theme: { extend: {} },
plugins: [],
}

# CSS ํŒŒ์ผ์— ์ถ”๊ฐ€
@tailwind base;
@tailwind components;
@tailwind utilities;

## 3. ๊ธฐ๋ณธ ์œ ํ‹ธ๋ฆฌํ‹ฐ
# ์—ฌ๋ฐฑ (Spacing)
p-4 # padding: 1rem
m-2 # margin: 0.5rem
px-6 # padding-left/right: 1.5rem
my-auto # margin-top/bottom: auto
space-x-4 # ์ž์‹ ์š”์†Œ ๊ฐ„ ๊ฐ„๊ฒฉ

# ํฌ๊ธฐ (Sizing)
w-full # width: 100%
w-1/2 # width: 50%
h-screen # height: 100vh
max-w-md # max-width: 28rem
min-h-0 # min-height: 0

## 4. ํƒ€์ดํฌ๊ทธ๋ž˜ํ”ผ
text-sm # font-size: 0.875rem
text-lg # font-size: 1.125rem
text-2xl # font-size: 1.5rem
font-bold # font-weight: 700
font-medium # font-weight: 500
leading-tight # line-height: 1.25
tracking-wide # letter-spacing: 0.025em
text-center # text-align: center

## 5. ์ƒ‰์ƒ
text-gray-500 # ํ…์ŠคํŠธ ์ƒ‰์ƒ
bg-blue-500 # ๋ฐฐ๊ฒฝ์ƒ‰
border-red-300 # ํ…Œ๋‘๋ฆฌ ์ƒ‰์ƒ
text-white # ํฐ์ƒ‰ ํ…์ŠคํŠธ
bg-gradient-to-r from-purple-500 to-pink-500

# ํˆฌ๋ช…๋„
bg-black/50 # 50% ํˆฌ๋ช…๋„
text-white/80 # 80% ํˆฌ๋ช…๋„

## 6. Flexbox
flex # display: flex
flex-col # flex-direction: column
items-center # align-items: center
justify-between # justify-content: space-between
gap-4 # gap: 1rem
flex-wrap # flex-wrap: wrap
flex-1 # flex: 1 1 0%

# ์˜ˆ์‹œ
<div class="flex items-center justify-between gap-4">
<div>Left</div>
<div>Right</div>
</div>

## 7. Grid
grid # display: grid
grid-cols-3 # 3์—ด ๊ทธ๋ฆฌ๋“œ
grid-cols-12 # 12์—ด ๊ทธ๋ฆฌ๋“œ
col-span-2 # 2์นธ ์ฐจ์ง€
gap-6 # gap: 1.5rem
grid-rows-2 # 2ํ–‰ ๊ทธ๋ฆฌ๋“œ

# ์˜ˆ์‹œ
<div class="grid grid-cols-3 gap-4">
<div>1</div>
<div class="col-span-2">2-3</div>
</div>

## 8. ๋ฐ˜์‘ํ˜• ๋””์ž์ธ
# ๋ธŒ๋ ˆ์ดํฌํฌ์ธํŠธ
sm: 640px
md: 768px
lg: 1024px
xl: 1280px
2xl: 1536px

# ์‚ฌ์šฉ๋ฒ• (๋ชจ๋ฐ”์ผ ์šฐ์„ )
<div class="w-full md:w-1/2 lg:w-1/3">
๋ชจ๋ฐ”์ผ: 100%, ํƒœ๋ธ”๋ฆฟ: 50%, ๋ฐ์Šคํฌํƒ‘: 33%
</div>

<div class="flex flex-col md:flex-row">
๋ชจ๋ฐ”์ผ: ์„ธ๋กœ, ํƒœ๋ธ”๋ฆฟ+: ๊ฐ€๋กœ
</div>

## 9. ๋‹คํฌ๋ชจ๋“œ
# tailwind.config.js
module.exports = {
darkMode: "class", // ๋˜๋Š” "media"
}

# ์‚ฌ์šฉ
<div class="bg-white dark:bg-gray-900">
<p class="text-gray-900 dark:text-white">Hello</p>
</div>

# ํ† ๊ธ€
document.documentElement.classList.toggle("dark")

## 10. ์ƒํƒœ ๋ณ€ํ˜•
hover:bg-blue-600 # ๋งˆ์šฐ์Šค ์˜ค๋ฒ„
focus:outline-none # ํฌ์ปค์Šค
active:scale-95 # ํด๋ฆญ ์‹œ
disabled:opacity-50 # ๋น„ํ™œ์„ฑํ™”
group-hover: # ๊ทธ๋ฃน ํ˜ธ๋ฒ„

# ์˜ˆ์‹œ
<button class="bg-blue-500 hover:bg-blue-600 active:scale-95 transition">
Click me
</button>

## 11. ์• ๋‹ˆ๋ฉ”์ด์…˜
transition # ๊ธฐ๋ณธ ํŠธ๋žœ์ง€์…˜
duration-300 # 0.3์ดˆ
ease-in-out # ์ด์ง•
transform # transform ํ™œ์„ฑํ™”
hover:scale-105 # ํ™•๋Œ€
animate-spin # ํšŒ์ „ ์• ๋‹ˆ๋ฉ”์ด์…˜
animate-pulse # ํŽ„์Šค ์• ๋‹ˆ๋ฉ”์ด์…˜
animate-bounce # ๋ฐ”์šด์Šค

## 12. ์ปค์Šคํ„ฐ๋งˆ์ด์ง•
# tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
primary: "#6366f1",
secondary: "#ec4899",
},
fontFamily: {
sans: ["Pretendard", "sans-serif"],
},
spacing: {
128: "32rem",
},
},
},
}

## ์ถ”์ฒœ ํ•™์Šต ์ˆœ์„œ
1. ๊ธฐ๋ณธ ์œ ํ‹ธ๋ฆฌํ‹ฐ ์ตํžˆ๊ธฐ
2. Flexbox/Grid ๋ ˆ์ด์•„์›ƒ
3. ๋ฐ˜์‘ํ˜• ๋””์ž์ธ
4. ๋‹คํฌ๋ชจ๋“œ ๊ตฌํ˜„
5. ์ปดํฌ๋„ŒํŠธ ํŒจํ„ด ๋งŒ๋“ค๊ธฐ