๐ŸŽ‰ berenickt ๋ธ”๋กœ๊ทธ์— ์˜จ ๊ฑธ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค. ๐ŸŽ‰
Front
TailwindCSS
01-Tailwindcss

1. Tailwindcss

https://tailwindcss.com/docs/installation

  • Utility-first CSS framework,
    • ์ฆ‰ ๋ฏธ๋ฆฌ ์ •์˜๋œ CSS์˜ ํŠน์„ฑ๋“ค์„ class ๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์™€ ์ ์šฉ์‹œํ‚ค๋Š” ํ˜•ํƒœ์˜ CSS ํ”„๋ ˆ์ž„์›Œํฌ
    • ์›ํ•˜๋Š” html ์š”์†Œ์— class ์„ ๋ถ€์—ฌํ•ด์ฃผ๋ฉด ๋ฐ”๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค
  • Tailwind CSS: CSS ํ”„๋ ˆ์ž„์›Œํฌ. ๋ฏธ๋ฆฌ ์ •์˜๋œ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ HTML ์Šคํƒ€์ผ์„ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ
    • e.g.) bg-blue-500 ํด๋ž˜์Šค๋ฅผ ์ ์šฉํ•˜๋ฉด, ๋”ฐ๋กœ CSS ์Šคํƒ€์ผ๋ง ์—†์ด๋„ ํŒŒ๋ž€ ๋ฐฐ๊ฒฝ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ
    • e.g.) px-4, mx-4 ํด๋ž˜์Šค๋“ค์„ ์ ์šฉํ•˜๋ฉด, ๋”ฐ๋กœ CSS ์Šคํƒ€์ผ๋ง ์—†์ด๋„ padding, margin ๊ด€๋ฆฌ ๊ฐ€๋Šฅ
  • ํด๋ž˜์Šค ๊ธฐ๋ฐ˜: Utility-first๋ผ๋Š” ๊ฐœ๋…ํ•˜์— ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ ์Šคํƒ€์ผ๋ง ๊ฐ€๋Šฅ. HTML๊ณผ CSS์˜ ๋ถ„๋ฆฌ๋ฅผ ์ตœ์†Œํ™”ํ•˜๊ณ  ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’์ž„
  • ์ปค์Šคํ…€ ์„ค์ •: tailwind.config.js ํŒŒ์ผ์„ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ •์˜ ์Šคํƒ€์ผ ๋ฐ ๊ตฌ์„ฑ ์ œ๊ณต
  • ์ผ๊ด€๋œ ๋””์ž์ธ: ๋ฏธ๋ฆฌ ์ •์˜๋œ ํด๋ž˜์Šค๋กœ ์ผ๊ด€์„œ ์žˆ๋Š” ๋””์ž์ธ ๊ตฌํ˜„ ๊ฐ€๋Šฅ
  • ๋ฐ˜์‘ํ˜• ์Šคํƒ€์ผ๋ง: ๋ฏธ๋””์–ด ํฌ๊ธฐ์— ๋งž๋Š” ๋ฐ˜์‘ํ˜• ๋””์ž์ธ์„ ์ง€์›ํ•˜๋ฉฐ, ํด๋ž˜์Šค ์ ‘๋‘์‚ฌ๋กœ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ œ์–ด ๊ฐ€๋Šฅ
  • ํ’๋ถ€ํ•œ ์ž๋ฃŒ: ๊ฑฐ๋Œ€ํ•œ ์ปค๋ฎค๋‹ˆํ‹ฐ์™€ ํ’๋ถ€ํ•œ ์ž๋ฃŒ, ๊ทธ๋ฆฌ๊ณ  Tailwind๋ฅผ ์ด์šฉํ•œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ปดํฌ๋„ŒํŠธ๋“ค
  • Tailwind CSS ๊ณต์‹ ๋ฌธ์„œ: https://tailwindcss.com/docs/installation

cf. VSCode ํ™•์žฅ๊ธฐ๋Šฅ

  • Tailwind CSS IntelliSense : ํด๋ž˜์Šค๋ช… ์ž๋™์™„์„ฑ
  • Tailwind Docs : ๋ฌธ์„œ ์ฐพ์•„๋ณผ ๋–„ Ctrl + Shipt + P๋กœ ๊ฒ€์ƒ‰

1.1 Tailwind ์ฃผ์š” ๊ฐœ๋…

  • Utility-First Fundamentals (์œ ํ‹ธ๋ฆฌํ‹ฐ-ํผ์ŠคํŠธ ๊ธฐ๋ณธ ์›์น™)
  • Handling Hover, Focus, and Other States (ํ˜ธ๋ฒ„, ํฌ์ปค์Šค ๋ฐ ๋‹ค๋ฅธ ์ƒํƒœ ์ฒ˜๋ฆฌ)
  • Responsive Design (๋ฐ˜์‘ํ˜• ๋””์ž์ธ)
  • Dark Mode (๋‹คํฌ๋ชจ๋“œ)
  • Reusing Styles (์Šคํƒ€์ผ ์žฌ์‚ฌ์šฉ)
  • Adding Custom Styles (์ปค์Šคํ…€ ์Šคํƒ€์ผ ์ถ”๊ฐ€)
  • Functions & Directives (ํ•จ์ˆ˜ ๋ฐ ๋””๋ ‰ํ‹ฐ๋ธŒ)
  • cf. Tailwind CSS ๊ณต์‹ ๋ฌธ์„œ ์ฐธ๊ณ : https://tailwindcss.com/docs/utility-first

1.2 Tailwind CSS ์žฅ๋‹จ์ 

[์žฅ์ ]

  • ๋น ๋ฅธ ๊ฐœ๋ฐœ: ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ์Šคํƒ€์ผ๋ง์„ ํ†ตํ•ด ๋ณด๋‹ค ๋น ๋ฅด๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ์Œ
  • ์ปค์Šคํ„ฐ๋งˆ์ด์ง•: Tailwind ์„ค์ • ํŒŒ์ผ์„ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ์— ๋งž๊ฒŒ ์Šคํƒ€์ผ ์กฐ์ • ๊ฐ€๋Šฅ
  • ์žฌ์‚ฌ์šฉ์„ฑ: ํด๋ž˜์Šค๋ฅผ ์žฌ์‚ฌ์šฉํ•ด์„œ ์ผ๊ด€๋œ ๋””์ž์ธ ๊ตฌํ˜„ ๊ฐ€๋Šฅ
  • ๋ฐ˜์‘ํ˜•: ํด๋ž˜์Šค ์ ‘๋‘์‚ฌ๋กœ ๋ฐ˜์‘ํ˜• ๋””์ž์ธ์„ ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Œ (ex. lg:text-red-500, md:p-4)

[๋‹จ์ ]

  • ํŒŒ์ผ ํฌ๊ธฐ: Tailwind๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ตฌํ˜„ํ•˜๋ฉด ํด๋ž˜์Šค๊ฐ€ ๋ณต์žกํ•ด์ง€๊ณ , ํŒŒ์ผ ํฌ๊ธฐ๊ฐ€ ์ปค์งˆ ์ˆ˜ ์žˆ์Œ
  • ํ•™์Šต ๊ณก์„ : ์ฒ˜์Œ์—๋Š” ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ์Šคํƒ€์ผ๋ง์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•„, ์ดˆ๊ธฐ ํ•™์Šต ๋น„์šฉ์ด ๋งŽ์ด ๋“ค์–ด๊ฐ

2. ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

https://tailwindcss.com/docs/installation

1
npm install -D tailwindcss
2
npx tailwindcss init

tailwindcss๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ๋กœ, ํŒŒ์ผ ์ž‘์„ฑ(ํ™•์žฅ์ž๋ช…์€ ๋„์›Œ์“ฐ๋ฉด ์•ˆ๋จ)

1
/** @type {import('tailwindcss').Config} */
2
module.exports = {
3
content: ['./src/**/*.{html,js,jsx,ts,tsx}'],
4
theme: {
5
extend: {},
6
},
7
plugins: [],
8
}

์ „์—ญ CSS์— ๋‹ค์Œ ์ฝ”๋“œ ์ถ”๊ฐ€ (CRA์—์„œ๋Š” index.css ๋งจ ์œ„์— ์ถ”๊ฐ€)

1
/* tailwind ๊ธฐ๋ณธ ์Šคํƒ€์ผ ๋ฐ ํ™•์žฅ๋œ ์Šคํƒ€์ผ ์ฃผ์ž… */
2
@tailwind base;
3
4
/* tailwind ๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค ๋ฐ ํ™•์žฅ๋œ ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค ์ฃผ์ž… */
5
@tailwind components;
6
7
/* tailwind ๊ธฐ๋ณธ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค ๋ฐ ํ™•์žฅ๋œ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค ์ฃผ์ž… */
8
@tailwind utilities;

2.1 Background

1
import React from 'react'
2
3
export default function Background() {
4
return (
5
<div className="bg-gray-700" style={{ height: 600 }}>
6
<div style={{ height: 100 }}>
7
<div style={{ height: 'inherit' }} class="bg-sky-500/100"></div>
8
<div style={{ height: 'inherit' }} class="bg-sky-500/75"></div>
9
<div style={{ height: 'inherit' }} class="bg-sky-500/50"></div>
10
</div>
11
</div>
12
)
13
}

2.2 TailwindExample

1
import Background from './Background'
2
3
export default function TailwindExample() {
4
return (
5
<div>
6
<Background />
7
</div>
8
)
9
}

2.3 App.js

1
// Webpack CSS import
2
// import 'onsenui/css/onsenui.css';
3
// import 'onsenui/css/onsen-css-components.css';
4
// import OnesenUIExample from './components/OnsenUI/OnesenUIExample';
5
// import AntDesignExample from './components/AntDesign/AntDesignExample';
6
// import 'semantic-ui-css/semantic.min.css';
7
// import ReactSemanticUIExample from './components/ReactSemanticUI/ReactSemanticUIExample';
8
// import 'bootstrap/dist/css/bootstrap.min.css';
9
// import ReactBootstrapExample from './components/ReactBootstrap/ReactBootstrapExample';
10
// import MaterialUIExample from './components/MaterialUI/MaterialUIExample';
11
import TailwindExample from './components/Tailwind/TailwindExample'
12
13
export default function App() {
14
return (
15
<>
16
<TailwindExample />
17
{/* <MaterialUIExample /> */}
18
{/* <ReactBootstrapExample /> */}
19
{/* <ReactSemanticUIExample /> */}
20
{/* <AntDesignExample /> */}
21
{/* <OnesenUIExample /> */}
22
</>
23
)
24
}

3. Next.js์—์„œ Tailwind CSS ์‚ฌ์šฉ

(1) yarn์œผ๋กœ Tailwind CSS ์„ค์น˜ ํ›„, Tailwind CSS ๊ตฌ์„ฑ ํŒŒ์ผ ์ƒ์„ฑ์„ ์œ„ํ•ด tailwindcss init ์ปค๋งจ๋“œ ์ž…๋ ฅ

1
yarn add -D tailwindcss postcss autoprefixer
2
npx tailwindcss init -p

(2) PostCSS ์„ค์ • ํŒŒ์ผ์— Tailwind ์ถ”๊ฐ€

1
// postcss.config.js
2
module.exports = {
3
plugins: {
4
tailwindcss: {},
5
autoprefixer: {},
6
},
7
}

(3) TailwindCSS๋ฅผ ์ ์šฉํ•  ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ tailwind.config.js ์„ค์ • ํŒŒ์ผ์— ๋ช…์‹œํ•œ๋‹ค

1
import type { Config } from 'tailwindcss'
2
3
const config: Config = {
4
content: [
5
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
6
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
7
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
8
],
9
theme: {
10
extend: {},
11
},
12
plugins: [],
13
}
14
export default config

(4) Tailwind CSS๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ CSS ํŒŒ์ผ ์„ ์ƒ์„ฑํ•˜๊ณ  tailwindcss๋ฅผ import ํ•œ๋‹ค

1
/* globals.css */
2
@tailwind base;
3
@tailwind components;
4
@tailwind utilities;

(5) ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ณ , tailwind ํด๋ž˜์Šค๋ฅผ ์ ์šฉํ•œ๋‹ค


4. ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” Tailwind CSS ํด๋ž˜์Šค

Tailwind CSS ํด๋ž˜์Šค์—๋Š” ์ƒ‰์ƒ, ํฐํŠธ, ์—ฌ๋ฐฑ, ๊ธธ์ด, ๊ทธ๋ฆฌ๋“œ, ํ”Œ๋ ‰์Šค, ํ…Œ๋‘๋ฆฌ ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์†์„ฑ ์ •์˜ ๊ฐ€๋Šฅ

  • bg-{color}: ๋ฐฐ๊ฒฝ์ƒ‰์„ ์ง€์ •ํ•˜๋Š” ํด๋ž˜์Šค๋กœ, ์ƒ‰์ƒ ์ฝ”๋“œ ๋ฐ ์ด๋ฆ„ ์ •์˜ (e.g. bg-indigo-500)
  • text-{color}: ํ…์ŠคํŠธ ์ƒ‰์ƒ์„ ์ง€์ •ํ•˜๋Š” ํด๋ž˜์Šค๋กœ, ์ƒ‰์ƒ ์ฝ”๋“œ ๋ฐ ์ด๋ฆ„ ์ •์˜ (e.g. text-red-700)
  • font-{weight}: ํฐํŠธ ๊ตต๊ธฐ๋ฅผ ์ง€์ •ํ•˜๋Š” ํด๋ž˜์Šค๋กœ, ํฐํŠธ ๊ตต๊ธฐ ๋ฐ ์ด๋ฆ„ ์ •์˜ (e.g. font-bold, font-[700])
  • p-{size}, m-{size}: ํŒจ๋”ฉ ๋ฐ ๋งˆ์ง„์„ ์ง€์ •ํ•˜๋Š” ํด๋ž˜์Šค๋กœ, ๊ฐ๊ฐ์˜ ํŒจ๋”ฉ/๋งˆ์ง„ ํฌ๊ธฐ ์ •์˜ (e.g. p-2, m-2)
  • w-{size}, h-{size}: ๋„ˆ๋น„ ๋ฐ ๋†’์ด๋ฅผ ์ง€์ •ํ•˜๋Š” ํด๋ž˜์Šค๋กœ, ๊ฐ๊ฐ์˜ ๋„ˆ๋น„/๋†’์ด ํฌ๊ธฐ ์ •์˜ (e.g. w-1/2, h-64)
  • grid, flex: ๊ทธ๋ฆฌ๋“œ์™€ ํ”Œ๋ ‰์Šค๋ฅผ ์ •์˜ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค (e.g. grid grid-rows-4)
  • rounded-{radius}: ์š”์†Œ๋ฅผ ๋‘ฅ๊ธ€๊ฒŒ ๋งŒ๋“œ๋Š” ํด๋ž˜์Šค (e.g. rounded-lg)
  • border-{width}: ํ…Œ๋‘๋ฆฌ์˜ ๊ตต๊ธฐ๋ฅผ ์ •์˜ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค (e.g. border-4)

4.1 Utility-First Fundamentals

  • TailwindCSS๋Š” ํด๋ž˜์Šค ๊ธฐ๋ฐ˜์˜ ์Šคํƒ€์ผ๋ง์„ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋‹ค์–‘ํ•œ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ์Šคํƒ€์ผ ์ ์šฉ
  • bg-blue-500: ๋ฐฐ๊ฒฝ์ƒ‰์„ ํŒŒ๋ž€์ƒ‰์œผ๋กœ ์ง€์ •
  • text-white: ํ…์ŠคํŠธ ์ƒ‰์ƒ์„ ํฐ์ƒ‰์œผ๋กœ ์ง€์ •
  • p-4: ํŒจ๋”ฉ์„ ํฌ๊ธฐ 4๋กœ ์ง€์ •

4.2 Handling Hover, Focus, and Other States

  • Tailwind CSS๋Š” hover, focus ๋ฐ ๋‹ค๋ฅธ ์ƒํƒœ์— ๋Œ€ํ•œ ํด๋ž˜์Šค๋“ค์„ ์ œ๊ณตํ•˜์—ฌ ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š” ์Šคํƒ€์ผ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
  • hover:bg-red-700 : ๋งˆ์šฐ์Šค ํ˜ธ๋ฒ„ ์ƒํƒœ์—์„œ ๋ฐฐ๊ฒฝ์ƒ‰ ๋ณ€๊ฒฝ
  • focus:bg-red-700 : ํฌ์ปค์Šค์‹œ ๋ฐฐ๊ฒฝ์ƒ‰ ๋ณ€๊ฒฝ
  • focus:outline-none : ํฌ์ปค์Šค์‹œ ๊ธฐ๋ณธ ์•„์›ƒ๋ผ์ธ ์ œ๊ฑฐ

4.3 Responsive Design

  • Tailwind๋Š” ๋ฐ˜์‘ํ˜• ๋””์ž์ธ์„ ์œ„ํ•œ ํด๋ž˜์Šค๋ฅผ ์ œ๊ณตํ•˜๋ฉฐ, ํ™”๋ฉด ํฌ๊ธฐ์— ๋”ฐ๋ผ ์Šคํƒ€์ผ ์กฐ์ ˆ ๊ฐ€๋Šฅ
  • e.g. md:bg-red-500์€ ์ค‘๊ฐ„ ํฌ๊ธฐ ํ™”๋ฉด์—์„œ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋นจ๊ฐ•์œผ๋กœ ๋ณ€๊ฒฝ

4.4 Dark Mode

  • Tailwind ๋‹คํฌ ๋ชจ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ํด๋ž˜์Šค๋ฅผ ์ œ๊ณตํ•˜๋ฉฐ,
    • ๋‹คํฌ ํ…Œ๋งˆ์™€ ๋ผ์ดํŠธ ํ…Œ๋งˆ ๊ฐ„ ์ „ํ™˜ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Œ
  • dark:bg-gray-800 : ๋‹คํฌ๋ชจ๋“œ์—์„œ ๋ฐฐ๊ฒฝ์ƒ‰์„ ์–ด๋‘ก๊ฒŒ ๋ณ€๊ฒฝ
  • dark:text-white : ๋‹คํฌ๋ชจ๋“œ์—์„œ ํ…์ŠคํŠธ ์ƒ‰์ƒ ๋ณ€๊ฒฝ

4.5 Reusing Styles

  • Tailwind๋Š” ํด๋ž˜์Šค๋ฅผ ์กฐํ•ฉํ•ด์„œ ์Šคํƒ€์ผ์„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์‚ฌ์šฉ์ž ์ •์˜ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Œ
  • ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค ์ฝ”๋“œ๋“ค์„ ๋งค๋ฒˆ ์ปดํฌ๋„ŒํŠธ๋งˆ๋‹ค ๋˜‘๊ฐ™์ด ๋ณต์‚ฌํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ,
    • ํ•˜๋‚˜์˜ ํด๋ž˜์Šค๋กœ ์ •๋ฆฌํ•ด์„œ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
  • btn-primary : ๋ฏธ๋ฆฌ ์ •์˜๋œ ํด๋ž˜์Šค๋ฅผ ์กฐํ•ฉํ•˜์—ฌ ์žฌ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์Šคํƒ€์ผ์„ ์ƒ์„ฑํ•จ

4.6 Adding Custom Styles

  • tailwind.config.js ํŒŒ์ผ์„ ํ†ตํ•ด์„œ ์‚ฌ์šฉ์ž ์ •์˜ ์Šคํƒ€์ผ ๋ฐ ์ปค์Šคํ…€ ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Œ
  • colors์— ์›ํ•˜๋Š” ์ƒ‰์ƒ์„ ์ถ”๊ฐ€ํ•˜์—ฌ, tailwind์—์„œ ์‚ฌ์ „์— ์ •์˜ํ•œ ์ƒ‰์ƒ์ด ์•„๋‹Œ, ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” ์ƒ‰์ƒ์œผ๋กœ ์ปค์Šคํ…€ ๊ฐ€๋Šฅ
  • e.g. bg-blue: ๊ธฐ์กด tailwind ์ƒ‰์ƒ์ด ์•„๋‹Œ, #1fb6ff ์ƒ‰์ƒ์œผ๋กœ ๋‚˜์˜ด

4.7 Functions & Directives

  • Tailwind์˜ ํ•จ์ˆ˜์™€ ๋””๋ ‰ํ‹ฐ๋ธŒ๋Š” Tailwind๋ฅผ ๋”์šฑ ํ™•์žฅ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๊ณ , ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ๋•Œ ์œ ์šฉ
  • Tailwind์—์„œ๋Š” ํ…Œ๋งˆ ๊ฐ’์„ ๋™์ ์œผ๋กœ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” theme() ํ•จ์ˆ˜์™€
    • ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ๋™์ ์œผ๋กœ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” screen() ํ•จ์ˆ˜๋ฅผ ์ œ๊ณต
  • ๋˜ํ•œ, Tailwind๋งŒ์˜ @๊ทœ์น™(at-rule) ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์กฐ๊ฑด์— ๋”ฐ๋ผ ์š”์†Œ์˜ ์Šคํƒ€์ผ์„ ์กฐ์ ˆ ๊ฐ€๋Šฅ
    • @tailwind: HTML ์š”์†Œ์— Tailwind CSS ํด๋ž˜์Šค๋ฅผ ๋™์ ์œผ๋กœ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
    • @layer: CSS ๊ทœ์น™์„ ๋ ˆ์ด์–ด๋ณ„๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ
    • @apply: CSS ํด๋ž˜์Šค๋ฅผ ๋™์ ์œผ๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ
    • @config: Tailwind CSS ๊ตฌ์„ฑ ์˜ต์…˜ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ

5. Tailwind CSS Tutorial

5.1 Tailwind Playground ์‹ค์Šต

1
<!-- 1.rem, px -->
2
<!-- <div class="w-4 w-[20px] w-4">111</div> -->
3
4
<!-- 2. bg, border, border-color, rounded -->
5
<!-- <div class="bg-pink-400 w-64 h-64 border-8 border-black rounded-[25px]">111</div> -->
6
7
<!-- 3. w, h, p(ํŒจ๋”ฉ), m(๋งˆ์ง„) -->
8
<!-- <div class="w-64 h-64 bg-pink-400 w-[350px] h-[350px] p-4 p-[20px] m-4 mx-10 my-20">111</div> -->
9
10
<!-- 4. text-color, text-size, font-bold, cursor -->
11
<!-- <div class="w-64 h-64 bg-black text-pink-400 text-[50px] font-[100] cursor-pointer">111</div> -->
12
13
<!-- 5. flex, flex-col, justify, item, gap -->
14
<!-- <div class="h-64 w-64 bg-pink-400 text-[50px] text-black flex justify-center itewms-center">111</div> -->
15
16
<!-- <div class="h-[750px] w-[750px] bg-black flex flex-col justify-center items-center gap-4">
17
<div class="flex h-64 w-64 items-center justify-center bg-pink-400 text-[50px] text-black">111</div>
18
<div class="flex h-64 w-64 items-center justify-center bg-pink-400 text-[50px] text-black">222</div>
19
</div> -->
20
21
<!-- 6. hover, transition -->
22
<!-- <div class="h-[750px] w-[750px] flex-col items-center justify-center gap-4 bg-black">
23
<div
24
class="hover:bg-purple-400 transition flex h-64 w-64 items-center justify-center bg-pink-400 text-[50px] text-black"
25
>
26
111
27
</div>
28
<div
29
class="hover:text-purple-400 transition-colors flex h-64 w-64 items-center justify-center bg-pink-400 text-[50px] text-black"
30
>
31
222
32
</div>
33
</div> -->
34
35
<!-- e.g. ํ”ฝํŠธ๋กœ๊ทธ๋žจ -- ์‹ ํ˜ธ๋“ฑ + ํšก๋‹จ๋ณด๋„ -->
36
<section class="bg-neutral-700 flex flex-row justify-between items-center h-[250px] w-full group">
37
<div class="flex flex-row gap-4 group-hover:bg-yellow-400">
38
<div class="w-4 h-[150px] bg-white"></div>
39
<div class="w-4 h-[150px] bg-white"></div>
40
<div class="w-4 h-[150px] bg-white"></div>
41
<div class="w-4 h-[150px] bg-white"></div>
42
<div class="w-4 h-[150px] bg-white"></div>
43
</div>
44
<div class="flex flex-row justify-center items-center gap-3">
45
<div class="w-32 h-32 bg-red-500 rounded-full border-2 border-black hover:bg-red-300 transition"></div>
46
<div class="w-32 h-32 bg-yellow-500 rounded-full border-2 border-black hover:bg-yellow-300 transition"></div>
47
<div class="w-32 h-32 bg-green-500 rounded-full border-2 border-black hover:bg-green-300 transition"></div>
48
</div>
49
<div class="flex flex-row gap-4 group-hover:bg-pink-400">
50
<div class="w-4 h-[150px] bg-white"></div>
51
<div class="w-4 h-[150px] bg-white"></div>
52
<div class="w-4 h-[150px] bg-white"></div>
53
<div class="w-4 h-[150px] bg-white"></div>
54
<div class="w-4 h-[150px] bg-white"></div>
55
</div>
56
</section>

5.2 ์ฐธ๊ณ  : Prettier

1
npm install -D prettier prettier-plugin-tailwindcss

ํ•ด๋‹น ํ”Œ๋Ÿฌ๊ทธ์ธ์€ tailwindcss ๊ณต์‹ Prettier ํ”Œ๋Ÿฌ๊ทธ์ธ์ž…๋‹ˆ๋‹ค. ํด๋ž˜์Šค๋ช…์„ tailwindcss๊ฐ€ ์ •ํ•œ ๊ธฐ์ค€๋Œ€๋กœ ๋‚˜์—ดํ•ด์ฃผ๋‹ˆ ํ•œ๊ฒฐ ์ฝ”๋“œ๊ฐ€ ๊น”๋”ํ•ด์ง


5.3 ์งง์€ ๊ฐ•์˜๋“ค