Lesson 34 +35 XP

Project 5: Class Timetable

Tables are real-world HTML - a timetable is the perfect table to build.

The goals

  1. A <table> with a <caption>.
  1. <thead> with the days and <tbody> with the periods.
  1. A cell that spans two columns with colspan and one that spans rows with rowspan.

Layout

Periods down, days across:

Code

html
<table>
  <caption>Weekly Timetable</caption>
  <thead>
    <tr>
      <th>Period</th><th>Mon</th><th>Tue</th><th>Wed</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th><td>Math</td><td>English</td><td>Math</td>
    </tr>
    <tr>
      <th>2</th><td colspan="2">Science</td><td>Art</td>
    </tr>
    <tr>
      <th>3</th><td rowspan="2">P.E.</td><td>Music</td><td>History</td>
    </tr>
  </tbody>
</table>

Staying straight

  • Use &lt;th&gt; for headers - they announce the row/column.
  • Use &lt;caption&gt; right after &lt;table&gt;.
  • colspan fills cells to the right; rowspan fills cells below.
  • Keep one cell per column per row, even when one spans over them!

Checklist

  • [ ] &lt;table&gt; with a &lt;caption&gt;
  • [ ] &lt;thead&gt; and &lt;tbody&gt;
  • [ ] At least one colspan
  • [ ] At least one rowspan
  • [ ] &lt;th&gt; for every header cell

TL;DR

Tables: table &gt; thead/tbody + tr &gt; th/td. colspan and rowspan merge cells.