Boxes and sections
หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
กล่องและส่วนแบ่ง
- Bigger pages need structure — clear areas, not one long pile.
- A
<div>is a plain box. A<span>is a small inline box for a few words. - Boxes group things together, so you can arrange and style them later.
ส่วนที่มีชื่อระบุ
- HTML มีกล่องพิเศษที่มีชื่อบ่งบอกความหมาย:
<header>(top),<main>(the main content),<footer>(bottom),<nav>(menu links).- They work like
<div>, but the names tell people — and search engines — what each part is.
English
<header>
<h1>My site</h1>
</header>
<main>
<p>Welcome to my page.</p>
</main>
<footer>
<small>Made by me</small>
</footer>
คลาสกำหนดชื่อกล่องของคุณ
- class คือฉลากที่คุณเพิ่มให้กับแท็ก:
<div class="card"> - It does nothing on its own — but soon, CSS will use it to style that box.
- นี่คือสะพานเชื่อมเข้าสู่ครึ่งหลังของบทเรียน
ข้อผิดพลาดที่พบบ่อย
<div>เป็นบล็อก (ขึ้นบรรทัดใหม่);<span>เป็นอินไลน์ (คงอยู่ในบรรทัดเดิม)- ใช้แท็กเชิงความหมายอย่าง
<header>และ<nav>เมื่อเหมาะสม
ลองดูเลย
- Add a
<header>and a<footer>, then give a box a class. - บทเรียนถัดไป เราจะเริ่มต้นทำให้หน้าเว็บ ดูสวยงาม ด้วย CSS
สำรวจ
A box wraps its content
A <div> is a box: content surrounded by padding, border, margin.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Give the page a top and a bottom. Wrap the title in a <header>, and the small note in a <footer>.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Give this box a name so we can style it later. Add class="card" to the <div>.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Add a menu. Inside the <header>, after the title, add a <nav> with two links: Home ไป / และ About ไป /about. An address that starts with / is a page on the same site, so it needs no https://.