๐ก TIL 20230819 - Tailwind CSS ์ฅ๋จ์ , ์ฐ์ต์์
1. Tailwind CSS๋
Tailwind CSS๋ utility-first ์ปจ์ ์ ๊ฐ์ง CSS ํ๋ ์์ํฌ์ด๋ค.
- ๋ถํธ์คํธ๋ฉ๊ณผ ๋น์ทํ๊ฒ m-1(.m-1 {margin: 0.25rem}), flex(.flex {display: flex})์ ๊ฐ์ด ๋ฏธ๋ฆฌ ์ธํ ๋ ์ ํธ๋ฆฌํฐ ํด๋์ค๋ฅผ ํ์ฉํ๋ ๋ฐฉ์์ผ๋ก HTML ์ฝ๋ ๋ด์์ ์คํ์ผ๋ง์ ํ ์ ์๋ค.
- tailwind๋ ์ ๋ก ๋ฐํ์์ผ๋ก ๋์ํ๋ฉฐ ๋น ๋ฅด๊ณ , ์ ์ฐํ๋ค.
1) ์ฅ์
- ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ ๊ฐ์ ์ถ์ํ ์์ค์ ์ ๊ณตํด ์คํ์ผ์ ๋น ๋ฅด๊ฒ ์ ์ฉํ ์ ์์ด ์ฝ๋์ ๊ธธ์ด๊ฐ ์ค๊ณ , css ์์ ์๊ฐ์ด ์ ์ฝ๋๋ค.
- ์ปดํฌ๋ํธ ์์ฑ์ด ์ฝ๊ณ , ๊ด๋ฆฌ ๋ฐ ์ ์ง๋ณด์๊ฐ ํธํ๋ค.
- ์ปค์คํฐ๋ง์ด์ง์ด ์ฌ์ ์ํ๋ ๋๋ก ๋์์ธ์ ๋ฐ๊พธ๊ธฐ ์ฝ๊ณ , ๋ฐ์ํ ๋์์ธ ๊ตฌํ๋ ํธํ๋ค.
2) ๋จ์
- ์ฝ๋๊ฐ ๋ชป์๊ฒผ๋ค(?) - ์๋ ์ฝ๋ ์ฐธ๊ณ
<figure class="md:flex bg-slate-100 rounded-xl p-8 md:p-0 dark:bg-slate-800">
<img class="w-24 h-24 md:w-48 md:h-auto md:rounded-none rounded-full mx-auto" src="/sarah-dayan.jpg" alt="" width="384" height="512">
<div class="pt-6 md:p-8 text-center md:text-left space-y-4">
<blockquote>
<p class="text-lg font-medium">
“Tailwind CSS is the only framework that I've seen scale
on large teams. It’s easy to customize, adapts to any design,
and the build size is tiny.”
</p>
</blockquote>
<figcaption class="font-medium">
<div class="text-sky-500 dark:text-sky-400">
Sarah Dayan
</div>
<div class="text-slate-700 dark:text-slate-500">
Staff Engineer, Algolia
</div>
</figcaption>
</div>
</figure>
- ๋ฌ๋ ์ปค๋ธ : ์ด๋ฏธ ํด๋์ค๋ช ์ด ์ ํด์ ธ์๊ธฐ ๋๋ฌธ์, ์ฒ์ ์จ๋ณด๋ ์ฌ๋๋ค์ ํด๋์ค๋ช ์ ์ต์ํด์ง๋๋ฐ ์๊ฐ์ด ํ์ํ๋ค. ํ์ง๋ง `Tailwind CSS IntelliSense`์ ๊ฐ์ VS code ์ต์คํ ์ ์ ์ค์นํ๋ฉด ์๋์์ฑ์ด ๋๊ธฐ ๋๋ฌธ์ ์ด๋์ ๋ ์ปค๋ฒ๊ฐ ๊ฐ๋ฅํ๋ค. (๊ฐ์ธ์ ์ผ๋ก ์ด ํ์ฅ ํ๋ก๊ทธ๋จ ์์ผ๋ฉด tailwind css ๋ชป์ธ๋ฏ)
2. ์ค์น ๋ฐ ์ฌ์ฉ
1) ์ค์น
npm install tailwindcss
npm tailwindcss init // ์ค์ ํ์ผ tailwind.config.ts ์์ฑ
๋๋ Next.js ํ๋ก์ ํธ ์ธํ ์ ์๋์ ๊ฐ์ด ํฐ๋ฏธ๋์์ ์ ํํ ์ ์๊ธฐ๋ ํ๋ค.
2) tailwind.config.ts
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js}'],
theme: {
colors: {
'blue': '#1fb6ff',
'purple': '#7e5bef',
'pink': '#ff49db',
'orange': '#ff7849',
'green': '#13ce66',
'yellow': '#ffc82c',
'gray-dark': '#273444',
'gray': '#8492a6',
'gray-light': '#d3dce6',
},
fontFamily: {
sans: ['Graphik', 'sans-serif'],
serif: ['Merriweather', 'serif'],
},
extend: {
spacing: {
'8xl': '96rem',
'9xl': '128rem',
},
borderRadius: {
'4xl': '2rem',
}
}
},
}
3) ์ฌ์ฉ ์์
์ฐ์ต ๊ฒธ ์์๋ก ๋ง๋ค์ด ๋ณธ ๊ฒฐ๊ณผ๋ฌผ๊ณผ ์ฝ๋๋ ์๋์ ๊ฐ๋ค.
import profilePic from "@/assets/pic.jpg"
import chairPic from "@/assets/chair.webp"
import Image from "next/image";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft, faStar, faHeart } from "@fortawesome/free-solid-svg-icons";
const Home = () => {
return (
<div className="w-11/12 max-w-xl mx-auto py-20 px-10 flex flex-col space-y-10">
<div className="bg-white p-8 rounded-3xl shadow-xl">
<span className="font-semibold text-3xl">Select Item</span>
<div className="flex justify-between my-2">
<span className="text-gray-500">Grey Chair</span>
<span className="font-semibold">$19</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500">Tooly Table</span>
<span className="font-semibold">$80</span>
</div>
<div className="flex justify-between mt-2 pt-2 border-t-2 border-dashed">
<span className="font-semibold">Total</span>
<span className="font-semibold">$99</span>
</div>
<div className="flex justify-center">
<button className="w-40 py-3 mt-5 bg-red-400 text-white p-2 rounded-lg shadow-lg hover:bg-red-300 hover:-translate-y-1 transition ease-in-out duration-200 active:bg-red-400">
Checkout
</button>
</div>
</div>
<div className="bg-white overflow-hidden rounded-2xl shadow-xl">
<div className="bg-blue-500 p-6 pb-14">
<span className="text-white text-2xl font-medium">Profile</span>
</div>
<div className="rounded-3xl p-6 bg-white relative -top-5">
<div className="flex relative -top-16 items-end justify-between">
<div className="flex flex-col items-center">
<span className="text-sm text-gray-400 font-medium">Orders</span>
<span className="font-semibold">340</span>
</div>
<Image src={profilePic} alt="profile" className="w-24 h-24 rounded-full" />
<div className="flex flex-col items-center">
<span className="text-sm text-gray-400 font-medium">Spent</span>
<span className="font-semibold">$2,310</span>
</div>
</div>
<div className="relative flex flex-col items-center -mt-10">
<span className="text-lg font-semibold">
Jane Doe
</span>
<span className="text-sm text-gray-500">
New York, USA
</span>
</div>
</div>
</div>
<div className="bg-white p-10 rounded-2xl shadow-xl">
<div className="flex mb-5 justify-between">
<button><FontAwesomeIcon icon={faArrowLeft} /></button>
<div className="space-x-3 flex items-center">
<span className="font-semibold">
<FontAwesomeIcon icon={faStar} className="text-yellow-400 mr-1" />
4.9
</span>
<button>
<FontAwesomeIcon icon={faHeart} className="text-red-500 shadow-xl p-2 rounded-md" />
</button>
</div>
</div>
<Image src={chairPic} alt="chair" />
<div className="flex flex-col">
<span className="font-semibold text-xl tracking-tight">Swoon Lounge</span>
<span className="text-sm text-gray-500">Chair</span>
<div className="mt-1 mb-5 flex justify-between items-center">
<div className="space-x-2 flex">
<div className="w-6 h-6 rounded-full bg-stone-300" />
<div className="w-6 h-6 rounded-full bg-orange-300" />
<div className="w-6 h-6 rounded-full bg-indigo-400" />
</div>
<div className="flex items-center space-x-5">
<button className="rounded-lg bg-stone-300 active:bg-stone-400 flex justify-center items-center aspect-square w-10 text-xl text-gray-500">
-
</button>
<span className="text-xl">1</span>
<button className="rounded-lg bg-stone-300 active:bg-stone-400 flex justify-center items-center aspect-square w-10 text-xl text-gray-500">
+
</button>
</div>
</div>
<div className="mt-5 flex justify-between items-center">
<span className="text-2xl font-semibold">$450</span>
<button className="w-40 bg-stone-500 text-white p-3 rounded-lg shadow-xl hover:bg-stone-600 hover:-translate-y-1 transition ease-in-out duration-200">Add to Cart</button>
</div>
</div>
</div>
{/* <div className="bg-white p-10 rounded-2xl shadow-xl"></div> */}
</div>
);
};
export default Home;
3. ๊ฐ์ธ์ ์ธ ์๊ฐ
styled-components๋ฅผ ์ฌ์ฉํ์ ๋๋, ์ด๊ฒ h1์ธ์ง div์ธ์ง form์ธ์ง HTML ํ๊ทธ๋ค์ sematicํ๊ฒ ํ์ ํ๊ธฐ ์ด๋ ต๋ค๊ณ ๋๊ผ์๋๋ฐ, tailwind css๋ HTML ํ๊ทธ๋ค์ ํ๋์ ๋ณผ ์ ์๋ค๋ ์ ์์ ๊ฐ๋ ์ฑ์ด ๋ ์ข๋ค๊ณ ๋๊ปด์ก๋ค.
ํ์ง๋ง tailwind๋ฅผ ์ฒ์ ์ ํ์ ๋ ๋ฌดํ์ฆ์ ํ๋ ๋ฏํ className๋ค์ ๋ณด๊ณ '์๋ ์ด๊ฒ ๋ญ์ผ...?' ์ถ๊ธด ํ์๋ค. ๊ทธ๋ฐ๋ฐ ์์ ์์ ์ ๋๋ง ๋ง๋ค์ด๋ณด๋ ์ต์ํด์ง๋ฉด ๊ธ๋ฐฉ ํ์ ํ ์ ์๊ณ , ๋ฌด์๋ณด๋ค ์ฝ๋ ์์ฑํ ๋ ์๊ฐ์ด ๋จ์ถ๋๋ค๋ ๊ฒ์ ๋ฐ๋ก ์ฒด๊ฐํ ์ ์์๋ค.
๋ฌด์๋ณด๋ค๋ ๊ณต์ ๋ฌธ์๊ฐ ์ ๋์ด์์ด ๊ณต์ ๋ฌธ์๋ฅผ ์ฝ์ด๋ณด๋ฉด์ ๋ ์ต์ํด์ง๋ฉด ์ ์ธ ์ ์์ ๊ฒ ๊ฐ๋ค.
์ฐธ๊ณ ์ฌ์ดํธ
๋ ธ๋ง๋ ์ฝ๋ - [ํ์คํ] ์บ๋ฟ๋ง์ผ ํด๋ก ์ฝ๋ฉ
Hello Tailwind CSS! | ์ฅ์ , ๋จ์ , ์ฌ์ฉ๋ฒ
tailwind css์ ์ฅ๋จ์ ๊ณผ ์ฌ์ฉ๋ฒ
'โ๏ธ What I Learned > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TIL] Prisma, Planet scale ์ ์ ๋ฐ ์ฐ๊ฒฐ ๋ฐฉ๋ฒ (0) | 2023.08.22 |
---|---|
[TIL] Prisma์ ๋ํด (0) | 2023.08.20 |
[TIL] Next.js 13 - getStaticProps, getStaticPaths (feat. 12๋ฒ์ ์์์ getServerSideProps) (0) | 2023.08.18 |
[TIL] Next.js - SSR vs SSG vs ISR (0) | 2023.08.17 |
[TIL] Next.js - redirect์ rewrite (0) | 2023.08.16 |