Lộ trình cá nhânClaude Design & Generative UI: Thiết kế Giao diện Web, App & Prototype Tương tác bằng AI
6/7

Giáo trình tự học miễn phí · Dịch vụ hỗ trợ theo nhu cầu.

Bài 0635phút ước tínhCơ bản đến Thực chiến

6. Tối Ưu Responsive Đa Màn Hình (Mobile, Tablet, Desktop) & Chuyển Đổi Dark/Light Mode

Đảm bảo giao diện hiển thị hoàn hảo trên iPhone, iPad và màn hình 4K: Làm chủ Tailwind Breakpoints (`sm`, `md`, `lg`, `xl`) và biến CSS Dark Mode.

📱 Chiến Lược Mobile-First Với Tailwind CSS

  • Mặc định là Mobile: Viết CSS cho màn hình dọc điện thoại trước (Ví dụ: w-full flex-col).
  • Mở rộng theo Breakpoints:
  • sm: (640px): Màn hình điện thoại ngang / Tablet nhỏ.
  • md: (768px): Màn hình iPad / Tablet đứng (chuyển sang md:flex-row).
  • lg: (1024px): Màn hình Laptop / Desktop (mở rộng lưới lg:grid-cols-4).
  • Dark Mode: Sử dụng thuộc tính dark:bg-slate-900 dark:text-white tự động theo tùy chọn hệ thống.
example.py
// ResponsiveNavbar.tsx
import { useState } from 'react';
import { Menu, X, Sun, Moon } from 'lucide-react';

export function Navbar({ darkMode, setDarkMode }: any) {
  const [mobileMenuOpen, setMobileMenuOpen] = useState(false);

  return (
    <nav className="border-b border-slate-200 dark:border-slate-800 bg-white/80 dark:bg-slate-900/80 backdrop-blur sticky top-0 z-40">
      <div className="max-w-6xl mx-auto px-4 h-16 flex items-center justify-between">
        <div className="font-extrabold text-xl text-indigo-600 dark:text-indigo-400 tracking-tight">AI TINH GỌN</div>
        
        {/* Desktop Links */}
        <div className="hidden md:flex items-center gap-6 text-sm font-semibold text-slate-600 dark:text-slate-300">
          <a href="#" className="hover:text-indigo-600 dark:hover:text-indigo-400">Khóa học</a>
          <a href="#" className="hover:text-indigo-600 dark:hover:text-indigo-400">Dịch vụ</a>
          <a href="#" className="hover:text-indigo-600 dark:hover:text-indigo-400">Tài nguyên</a>
        </div>

        {/* Action Controls */}
        <div className="flex items-center gap-3">
          <button onClick={() => setDarkMode(!darkMode)} className="p-2 rounded-xl bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300">
            {darkMode ? <Sun className="w-4 h-4" /> : <Moon className="w-4 h-4" />}
          </button>
          <button onClick={() => setMobileMenuOpen(!mobileMenuOpen)} className="md:hidden p-2 text-slate-700 dark:text-slate-300">
            {mobileMenuOpen ? <X className="w-6 h-6" /> : <Menu className="w-6 h-6" />}
          </button>
        </div>
      </div>
    </nav>
  );
}
Thực hành

Thực hành và tự đánh giá

Kiểm tra giao diện của bạn trên công cụ Responsive Mode (F12) của trình duyệt ở các kích thước iPhone 14 Pro, iPad Air và Desktop 1920x1080.

⚖️ Bản quyền sở hữu trí tuệ: © 2026 AI Tinh Gọn (aitinhgon.vn) · Giấy phép Creative Commons CC BY-NC-ND 4.0. Cho phép tự học cá nhân, nghiêm cấm thương mại hóa hoặc bán lại. Giáo trình mở →

Tiến độ tự học lưu trên trình duyệt này. Chỉ đánh dấu khi đã kiểm tra sản phẩm thực hành.