# 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. ์ปดํฌ๋ํธ ํจํด ๋ง๋ค๊ธฐ