🌟Học nhanh Tailwind CSS trong 01h⏱️
🚀 0. Chuẩn bị trước khi bắt đầu (0–2 phút)
✅ Dùng công cụ online như:
-
Tailwind Play – viết & test code Tailwind trực tiếp
-
Hoặc dùng VSCode + CDN nhanh:
<script src="https://cdn.tailwindcss.com"></script>
⏱️ 1. Hiểu triết lý và class cơ bản (2–10 phút)
| Nội dung | Ví dụ |
|---|---|
| Utility-first = mỗi class làm đúng 1 việc | bg-red-500, text-white, p-4 |
| Cách đặt tên class = theo logic CSS | text-xl, rounded, shadow-lg, w-1/2 |
| Responsive = prefix theo kích thước | sm:, md:, lg:, xl: |
📌 Ví dụ:
<div class="text-center text-lg md:text-xl text-blue-600 p-4"> Hello Tailwind!</div>
⏱️ 2. Layout cơ bản (10–25 phút)
📦 Flex & Grid
<div class="flex justify-between items-center p-4 bg-gray-100"> <div>Logo</div> <div class="flex gap-4"> <a href="#">Home</a> <a href="#">About</a> </div></div><div class="grid grid-cols-2 md:grid-cols-4 gap-4 p-4"> <div class="bg-blue-200 p-4 rounded">Box 1</div> ...</div>
📏 Spacing & Size
<div class="p-6 m-4 w-1/2 max-w-sm">Content</div>
⏱️ 3. Màu sắc & Typography (25–35 phút)
<h1 class="text-2xl font-bold text-gray-800 mb-4">Tiêu đề</h1><p class="text-gray-600 leading-relaxed"> Đây là đoạn mô tả với line height dễ đọc.</p>
⏱️ 4. Hiệu ứng chuyển động & trạng thái (35–45 phút)
<button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition-colors duration-300"> Hover me</button>
| Tác dụng | Class |
|---|---|
| Hover | hover:bg-... |
| Transition | transition, duration-300 |
| Scale, fade | hover:scale-105, opacity-0 |
| Shadow | shadow, hover:shadow-lg |
⏱️ 5. Responsive thiết thực (45–55 phút)
<div class="text-base sm:text-lg md:text-xl lg:text-2xl"> Responsive Text</div><div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div class="bg-yellow-100 p-4">Card 1</div> ...</div>
⏱️ 6. Tái sử dụng: @apply + tổ chức layout (55–60 phút)
📦 File CSS:
@tailwind base;
@tailwind components;
@tailwind utilities;
.btn {
@apply bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition;
}
Dùng:
📁 Kết thúc: Tạo layout demo tổng hợp
file HTML demo layout tổng hợp các nội dung trên (navbar, card, hiệu ứng hover...) trong 1 file duy nhất.
🎁 Nếu muốn học tiếp, tôi đề xuất:
-
Học về
@layer,plugin,purge,dark mode -
Dựng component tái sử dụng (giống React-style)
-
Kết hợp Tailwind với framework như Vue, React hoặc Laravel
🌟 🤖 Made by AI – Tailwind trong 1 giờ: gọn, đủ, hiệu quả cho thực chiến! 🧩
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tailwind CSS Demo Layout</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 text-gray-800">
<!-- Navbar -->
<nav class="bg-white shadow p-4 flex justify-between items-center">
<div class="text-xl font-bold text-blue-600">🚀 MySite</div>
<div class="space-x-4">
<a href="#" class="text-gray-600 hover:text-blue-600 transition">Home</a>
<a href="#" class="text-gray-600 hover:text-blue-600 transition">About</a>
<a href="#" class="text-gray-600 hover:text-blue-600 transition">Contact</a>
</div>
</nav>
<!-- Hero Section -->
<header class="bg-blue-100 text-center py-12 px-4">
<h1 class="text-3xl md:text-5xl font-bold mb-4">Welcome to Tailwind Demo</h1>
<p class="text-lg md:text-xl text-blue-800">Build fast, beautiful UIs with utility-first CSS</p>
<button class="mt-6 bg-blue-500 text-white px-6 py-2 rounded hover:bg-blue-600 transition-all duration-300">
Get Started
</button>
</header>
<!-- Card Grid -->
<section class="p-6 grid grid-cols-1 md:grid-cols-3 gap-6 max-w-6xl mx-auto">
<div class="bg-white p-4 rounded shadow hover:shadow-lg transition">
<h2 class="text-xl font-semibold mb-2">📦 Card One</h2>
<p class="text-gray-600">This is a simple card with a shadow and hover effect.</p>
</div>
<div class="bg-white p-4 rounded shadow hover:shadow-lg transition">
<h2 class="text-xl font-semibold mb-2">🎯 Card Two</h2>
<p class="text-gray-600">Responsive design is built-in using utility classes.</p>
</div>
<div class="bg-white p-4 rounded shadow hover:shadow-lg transition">
<h2 class="text-xl font-semibold mb-2">🚀 Card Three</h2>
<p class="text-gray-600">Tailwind makes your UI clean and flexible fast.</p>
</div>
</section>
<!-- Footer -->
<footer class="text-center text-sm text-gray-500 p-4">
© 2025 Tailwind Demo. Built with ❤️ and Tailwind CSS.
</footer>
</body>
</html>
Nhận xét
Đăng nhận xét