0Pricing
Next.js 15 Fullstack Web Apps · บทเรียน

การออกแบบแบบตอบสนองและโหมดมืด

สร้างเลย์เอาต์ที่ปรับเข้ากับทุกหน้าจอด้วยจุดเปลี่ยนแบบเน้นมือถือก่อน และเพิ่มโหมดมืดที่ดูประณีตและคำนึงถึงผู้ใช้ด้วยตัวแปร CSS และ Tailwind

การออกแบบแบบตอบสนองและโหมดมืด เป็นบทเรียน Next.js 15 Fullstack Web Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Next.js 15 Fullstack Web Apps และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Next.js 15 Fullstack Web Apps มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Mobile-First Thinking

Responsive design means one layout that adapts to phones, tablets, and desktops. The modern approach is mobile-first: style the small screen first, then add enhancements for larger ones.

Media Queries

The CSS @media rule applies styles only above (or below) a width. Mobile-first uses min-width breakpoints.

.grid { display: block; }
@media (min-width: 768px) {
  .grid { display: grid; grid-template-columns: 1fr 1fr; }
}

Fluid Units

Prefer relative units so layouts scale naturally:

  • rem for spacing and font size
  • % and fr for widths
  • clamp() for fluid typography
h1 { font-size: clamp(1.5rem, 4vw, 3rem); }

Tailwind Breakpoints

Tailwind makes responsiveness inline with prefixes like sm:, md:, lg:. Unprefixed classes are the mobile base.

<div class="block md:grid md:grid-cols-2 lg:grid-cols-3">

Flexbox and Grid

Two layout engines cover almost everything:

  • Flexbox for one-dimensional rows or columns
  • Grid for two-dimensional layouts

Combine them and let breakpoints reflow content.

What Is Dark Mode?

Dark mode swaps a light palette for a dark one to reduce eye strain and save battery on OLED screens. A good implementation respects the user system preference and lets them override it.

System Preference

The CSS media feature prefers-color-scheme detects the OS theme so you can default to what the user already chose.

@media (prefers-color-scheme: dark) {
  body { background: #111; color: #eee; }
}

CSS Variables for Theming

Define colors as CSS custom properties on the root, then override them for dark mode. Components reference variables, so a single switch repaints the whole app.

:root { --bg: #fff; --fg: #111; }
[data-theme='dark'] { --bg: #111; --fg: #eee; }
body { background: var(--bg); color: var(--fg); }

Tailwind Dark Variant

Tailwind ships a dark: variant. Toggle a dark class on the html element and dark utilities activate.

<div class="bg-white text-black dark:bg-gray-900 dark:text-white">

Persisting the Choice

Store the user choice in localStorage and apply it before paint to avoid a flash of the wrong theme. Libraries like next-themes handle this cleanly in Next.js.

const theme = localStorage.getItem('theme') || 'system';
document.documentElement.dataset.theme = theme;

Accessibility & Contrast

Whatever the theme, keep text readable. Aim for a contrast ratio of at least 4.5:1 for body text per WCAG. Test both themes; a color that works on white may fail on dark.

Quick Check

Test your responsive and theming knowledge.

Recap

You learned adaptive styling:

  • Mobile-first media queries and fluid units adapt layouts
  • Tailwind md:/lg: prefixes make breakpoints inline
  • CSS variables plus prefers-color-scheme power dark mode
  • Persist the choice and keep contrast accessible in both themes

คำถามที่พบบ่อย

บทเรียน “การออกแบบแบบตอบสนองและโหมดมืด” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การออกแบบแบบตอบสนองและโหมดมืด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Next.js 15 Fullstack Web Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Next.js 15 Fullstack Web Apps มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การออกแบบแบบตอบสนองและโหมดมืด”

สร้างเลย์เอาต์ที่ปรับเข้ากับทุกหน้าจอด้วยจุดเปลี่ยนแบบเน้นมือถือก่อน และเพิ่มโหมดมืดที่ดูประณีตและคำนึงถึงผู้ใช้ด้วยตัวแปร CSS และ Tailwind คุณปฏิบัติ Next.js 15 Fullstack Web Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Next.js 15 Fullstack Web Apps หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Next.js 15 Fullstack Web Apps บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การออกแบบแบบตอบสนองและโหมดมืด” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Next.js 15 Fullstack Web Apps นี้ได้ไหม

ได้ บทเรียน Next.js 15 Fullstack Web Apps ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. โมดูล CSS และสไตล์ส่วนกลาง
  2. การผสานรวม Tailwind CSS
  3. ไลบรารีคอมโพเนนต์และการกำหนดธีม
  4. การออกแบบแบบตอบสนองและโหมดมืด
← กลับไปที่ Next.js 15 Fullstack Web Apps