Tailwind๋ ์ ํธ๋ฆฌํฐ ํผ์คํธ(Utility-first) CSS ํ๋ ์์ํฌ์
๋๋ค. ์ด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ฏธ๋ฆฌ ์ ์๋ ํด๋์ค๋ฅผ ํ์ฉํด ๋น ๋ฅด๊ฒ ์คํ์ผ๋งํ ์ ์๋๋ก ๋์์ฃผ๋ ํ๋ ์์ํฌ๋ฅผ ์๋ฏธํฉ๋๋ค. ๊ธฐ์กด์ CSS ๋ฐฉ์๊ณผ๋ ๋ค๋ฅด๊ฒ Tailwind๋ ๋ณ๋์ ์คํ์ผ ์ํธ๋ฅผ ์์ฑํ๋ ๋์ , HTML ํด๋์ค์ ์ง์ ์คํ์ผ๋ง ๊ด๋ จ ์ ํธ๋ฆฌํฐ ํด๋์ค๋ค์ ์ถ๊ฐํ๋ ๋ฐฉ์์ผ๋ก ์์
ํฉ๋๋ค.
์ ํธ๋ฆฌํฐ ํด๋์ค
Tailwind๋ ๊ฐ ์คํ์ผ์ ๋จ์ผ ํด๋์ค์ ์บก์ํํฉ๋๋ค.
์๋ฅผ ๋ค์ด, text-center, bg-blue-500, p-4์ ๊ฐ์ ํด๋์ค๋ฅผ ์กฐํฉํด ํ ์คํธ ์ ๋ ฌ, ๋ฐฐ๊ฒฝ์ ์ค์ , ํจ๋ฉ ๋ฑ์ ๊ฐ๋จํ๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, text-center, bg-blue-500, p-4์ ๊ฐ์ ํด๋์ค๋ฅผ ์กฐํฉํด ํ ์คํธ ์ ๋ ฌ, ๋ฐฐ๊ฒฝ์ ์ค์ , ํจ๋ฉ ๋ฑ์ ๊ฐ๋จํ๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.
๋ฐ์ํ ๋์์ธ
Tailwind๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ฐ์ํ ๋์์ธ์ ์ฝ๊ฒ ์ฒ๋ฆฌํ ์ ์๋๋ก ๋์์ค๋๋ค.
์๋ฅผ ๋ค์ด, md:text-center์ ๊ฐ์ด ํน์ ํ๋ฉด ํฌ๊ธฐ์์๋ง ์ ์ฉ๋ ์คํ์ผ์ ์ ์ํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, md:text-center์ ๊ฐ์ด ํน์ ํ๋ฉด ํฌ๊ธฐ์์๋ง ์ ์ฉ๋ ์คํ์ผ์ ์ ์ํ ์ ์์ต๋๋ค.
๋ฏธ๋ฆฌ ์ ์๋ ํ ๋ง
Tailwind๋ ์์, ๊ธ๊ผด ํฌ๊ธฐ, ์ฌ๋ฐฑ ๋ฑ์ ๋ฏธ๋ฆฌ ์ ์๋ ๊ฐ์ผ๋ก ์ ๊ณตํ๋ฉฐ, ์ด๋ฅผ ์ฝ๊ฒ ์ปค์คํฐ๋ง์ด์งํ ์ ์์ต๋๋ค.
์ ์ฐ์ฑ
Tailwind๋ ๋งค์ฐ ์ ์ฐํ์ฌ ํ๋ก์ ํธ์ ์คํ์ผ ๊ฐ์ด๋๋ฅผ ๋ฐ๋ฅด๋ฉด์๋ ์ธ๋ถ์ ์ผ๋ก ๋ค์ํ ์คํ์ผ์ ์ ์ฉํ ์ ์์ต๋๋ค.
JIT(Just-In-Time)
ํ์ํ ๋๋ง๋ค ์คํ์ผ์ ์์ฑํด ์ฃผ๋ JIT ๋ชจ๋๋ฅผ ์ง์ํ์ฌ, ์ฌ์ฉํ์ง ์๋ CSS ํด๋์ค๊ฐ ๋น๋์ ํฌํจ๋์ง ์๋๋ก ํฉ๋๋ค. ์ด๋ก ์ธํด ๋น๋ ํฌ๊ธฐ๋ฅผ ํฌ๊ฒ ์ค์ผ ์ ์์ต๋๋ค.
tailwond ํ ์คํธ ํฌ๊ธฐ ํด๋์ค(font-size)
ํ
์ผ์๋ CSS(Tailwind CSS)์์ ํฐํธ ํฌ๊ธฐ๋ text- ์ ๋์ฌ๋ฅผ ์ฌ์ฉํ์ฌ ์ค์ ํ๋ฉฐ, ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์ํ ํฌ๊ธฐ ํด๋์ค๋ฅผ ์ ๊ณตํฉ๋๋ค. ์๋๋ ํ
์ผ์๋์ ํฐํธ ํฌ๊ธฐ ํด๋์ค์ ์์์ ๊ทธ์ ํด๋นํ๋ ์ค์ ํฌ๊ธฐ์
๋๋ค. (Tailwind CSS v3.4 ๊ธฐ์ค)
<p class="text-xs">text-xs: 0.75rem (12px)</p> <p class="text-sm">text-sm: 0.875rem (14px)</p> <p class="text-base">text-base: 1rem (16px)</p> <p class="text-lg">text-lg: 1.125rem (18px)</p> <p class="text-xl">text-xl: 1.25rem (20px)</p> <p class="text-2xl">text-2xl: 1.5rem (24px)</p> <p class="text-3xl">text-3xl: 1.875rem (30px)</p> <p class="text-4xl">text-4xl: 2.25rem (36px)</p> <p class="text-5xl">text-5xl: 3rem (48px)</p> <p class="text-6xl">text-6xl: 3.75rem (60px)</p> <p class="text-7xl">text-7xl: 4.5rem (72px)</p> <p class="text-8xl">text-8xl: 6rem (96px)</p> <p class="text-9xl">text-9xl: 8rem (128px)</p>
ํด๋์ค | rem ํฌ๊ธฐ | px ํฌ๊ธฐ |
---|---|---|
text-xs | 0.75rem | 12px |
text-sm | 0.875rem | 14px |
text-base | 1rem | 16px |
text-lg | 1.125rem | 18px |
text-xl | 1.25rem | 20px |
text-xs | 0.75rem | 12px |
text-2xl | 1.5rem | 24px |
text-3xl | 1.875rem | 30px |
text-4xl | 2.25rem | 36px |
text-5xl | 3rem | 48px |
text-6xl | 3.75rem | 60px |
text-7xl | 4.5rem | 72px |
text-8xl | 6rem | 96px |
text-9xl | 8rem | 128px |
tailwond ํฐํธ ๋๊ป (font-weight)
<p class="font-thin">font-thin: font-weight: 100</p> <p class="font-extralight">font-extralight: font-weight: 200</p> <p class="font-light">font-light: font-weight: 300</p> <p class="font-normal">font-normal: font-weight: 400</p> <p class="font-medium">font-medium: font-weight: 500</p> <p class="font-semibold">font-semibold: font-weight: 600</p> <p class="font-bold">font-bold: font-weight: 700</p> <p class="font-extrabold">font-extrabold: font-weight: 800</p> <p class="font-black">font-black: font-weight: 900</p>
ํด๋์ค | font-weight |
---|---|
font-thin | 100 |
font-extralight | 200 |
font-light | 300 |
font-normal | 400 |
font-medium | 500 |
font-semibold | 600 |
font-bold | 700 |
font-extrabold | 800 |
font-black | 900 |
tailwond ๋ผ์ธ ๋์ด (line-height)
<p class="leading-none">leading-none: line-height: 1</p> <p class="leading-tight">leading-tight: line-height: 1.25</p> <p class="leading-snug">leading-snug: line-height: 1.375</p> <p class="leading-normal">leading-normal: line-height: 1.5</p> <p class="leading-relaxed">leading-relaxed: line-height: 1.625</p> <p class="leading-loose">leading-loose: line-height: 2</p> <p class="leading-3">leading-3: line-height: 0.75rem (12px)</p> <p class="leading-4">leading-4: line-height: 1rem (16px)</p> <p class="leading-5">leading-5: line-height: 1.25rem (20px)</p> <!-- leading-6 ~ leading-10๊น์ง ์ง์ -->
ํด๋์ค | line-height |
---|---|
leading-none | 1 |
leading-tight | 1.25 |
leading-snug | 1.375 |
leading-normal | 1.5 |
leading-relaxed | 1.625 |
leading-loose | 2 |
leading-3 | 0.75rem (12px) |
leading-4 | 1rem (16px) |
leading-5 | 1.25rem (20px) |
leading-6 | 1.5rem (24px) |
leading-7 | 1.75rem (28px) |
leading-8 | 2rem (32px) |
leading-9 | 2.25rem (36px) |
leading-10 | 2.5rem (40px) |
tailwond ๋ ํฐ ์คํ์ด์ฑ (letter-spacing)
<p class="tracking-tighter">tracking-tighter: letter-spacing: -0.05em</p> <p class="tracking-tight">tracking-tight: letter-spacing: -0.025em</p> <p class="tracking-normal">tracking-normal: letter-spacing: 0</p> <p class="tracking-wide">tracking-wide: letter-spacing: 0.025em</p> <p class="tracking-wider">tracking-wider: letter-spacing: 0.05em</p> <p class="tracking-widest">tracking-widest: letter-spacing: 0.1em</p>
ํด๋์ค | letter-spacing |
---|---|
tracking-tighter | -0.05em |
tracking-tight | -0.025em |
tracking-normal | 0 |
tracking-wide | 0.025em |
tracking-wider | 0.05em |
tracking-widest | 0.1em |
tailwond ํ ์ผ์๋ ์คํ์ด์ฑ ์ค์ผ์ผ
ํ
์ผ์๋์ ๋ง์ง(m-)๊ณผ ํจ๋ฉ(p-)์ ๋์ผํ ์คํ์ด์ฑ ์ค์ผ์ผ์ ๊ณต์ ํฉ๋๋ค.
- 1 ๋จ์ = 0.25rem = 4px (๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๋ฃจํธ ํฐํธ ํฌ๊ธฐ 1rem = 16px ๊ธฐ์ค)
- n ๊ฐ์ ๋ฐ๋ผ n * 0.25rem์ผ๋ก ๊ณ์ฐ
- ํ ์ผ์๋์ ์คํ์ด์ฑ ์์คํ ์ top, right, bottom, left ๋ฐฉํฅ์ ๋ํด ๋์ผํ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.
- ๋ง์ง: mt-n, mr-n, mb-n, ml-n์ ๋ชจ๋ ๋์ผํ n * 0.25rem ๊ฐ์ ๊ฐ์ง.
- ํจ๋ฉ: pt-n, pr-n, pb-n, pl-n๋ ๋์ผํ n * 0.25rem ๊ฐ์ ๊ฐ์ง.
<div class="mt-0">mt-0: margin-top: 0px</div> <!-- mr-0, mb-0, ml-0 ๋์ผ --> <div class="mt-1">mt-1: margin-top: 0.25rem (4px)</div> <!-- mr-1, mb-1, ml-1 ๋์ผ --> <div class="mt-2">mt-2: margin-top: 0.5rem (8px)</div> <!-- mr-2, mb-2, ml-2 ๋์ผ --> <div class="mt-3">mt-3: margin-top: 0.75rem (12px)</div> <!-- mr-3, mb-3, ml-3 ๋์ผ --> <div class="mt-4">mt-4: margin-top: 1rem (16px)</div> <!-- mr-4, mb-4, ml-4 ๋์ผ --> <div class="mt-5">mt-5: margin-top: 1.25rem (20px)</div> <!-- mr-5, mb-5, ml-5 ๋์ผ --> <div class="mt-6">mt-6: margin-top: 1.5rem (24px)</div> <!-- mr-6, mb-6, ml-6 ๋์ผ --> <div class="mt-7">mt-7: margin-top: 1.75rem (28px)</div> <!-- mr-7, mb-7, ml-7 ๋์ผ --> <div class="mt-8">mt-8: margin-top: 2rem (32px)</div> <!-- mr-8, mb-8, ml-8 ๋์ผ --> <div class="mt-9">mt-9: margin-top: 2.25rem (36px)</div> <!-- mr-9, mb-9, ml-9 ๋์ผ --> <div class="mt-10">mt-10: margin-top: 2.5rem (40px)</div> <!-- mr-10, mb-10, ml-10 ๋์ผ -->
mt-n, mr-n, mb-n, ml-n, pt-n, pr-n, pb-n, pl-n | ์ค์ผ์ผ |
---|---|
n=0 | 0px |
n=1 | 0.25rem (4px) |
n=2 | 0.5rem (8px) |
n=3 | 0.75rem (12px) |
n=4 | 1rem (16px) |
n=5 | 1.25rem (20px) |
n=6 | 1.5rem (24px) |
n=7 | 1.75rem (28px)) |
n=8 | 2rem (32px) |
n=9 | 2.25rem (36px) |
n=10 | 2.5rem (40px) |
tailwond ์ปค์คํ ์ค์ (tailwind.config.js)
/** @type {import('tailwindcss').Config} */ module.exports = { theme: { extend: { // ์ปค์คํ ํจ๋ฉ padding: { '10': '2.5rem', // 40px '12': '3rem', // 48px }, // ์ปค์คํ ๋ง์ง margin: { '10': '2.5rem', // 40px '12': '3rem', // 48px }, // ์ปค์คํ ํฐํธ ๋๊ป fontWeight: { 'extra-thin': 50, }, // ์ปค์คํ ๋ผ์ธ ๋์ด lineHeight: { 11: '2.75rem', // 44px 12: '3rem', // 48px }, // ์ปค์คํ ๋ ํฐ ์คํ์ด์ฑ letterSpacing: { 'extra-wide': '0.15em', }, }, }, };