制作课程表需用html 还原“时间×星期”二维结构: 定义星期表头, 每行以 标注节次,合理使用 rowspan/colspan 合并跨时段课程,确保语义清晰、列数对齐、可访问性强。

用 HTML <table> 制作课程表,核心是还原“时间 × 星期”的二维结构:<strong>行代表节次(或时段),列代表星期几</strong>。结构清晰、语义正确、合并合理,才能保证可读性、可访问性和后期样式控制。<h3>明确表头分区:用 `<thead>` 和 `<th>` 区分行列标题
课程表不是普通数据表,它有双重表头——横向是星期,纵向是节次。必须分开定义:
- `<thead>` 里放两行:第一行留空(对应左上角),后几列写“星期一”到“星期五”;
- 第二行可选加时段说明(如“上午”“下午”),或直接进入 `</thead>
</th>
</thead>
<tbody>`;
- 每个节次所在列首单元格要用 `<th scope="row">第1节</th>`,让屏幕阅读器知道这是行标题;
- 星期标题统一用 `<th>`,不用 `</th>
<td>`,语义更准确。
<p>错误做法:把“星期一”“第1节”全塞进 `</p>
</td>
<td>`;正确做法是第一行 `</td>
<th>` 写星期,第一列 `</th>
<th scope="row">` 写节次。<h3>规范使用 `rowspan` 和 `colspan` 合并跨时段课程</h3>
一节课连上两节、或横跨两天,不能靠空 `</th>
<td>` 填充,得用合并属性:
- 跨节次(竖向合并):在起始 `</td>
<td>` 加 `rowspan="2"`,下一行同一列就跳过,不写 `</td>
<td>`;
- 跨星期(横向合并):在起始 `</td>
<td>` 加 `colspan="2"`,后面一列就不再单独写 `</td>
<td>`;
- 避免 `rowspan` 和 `colspan` 嵌套(比如一个单元格既设 `rowspan` 又设 `colspan`),容易错位、打印异常;
- 所有行 `</td>
<tr>` 中 `<td>` 或 `</td>
<th>` 数量必须一致,等于表头 `</th>
<th>` 总数(含首列节次),否则表格会塌陷或错列。
<p>例如:周三第2–3节的课,就在“第2节”行、“周三”列的 `</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill7761" title="Article To Html"><img
src="https://img.php.cn/upload/skill/000/000/081/179168408018805.jpg" alt="Article To Html" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill7761" title="Article To Html" class="overflowclass">Article To Html</a>
<p class="overflowclass">文章转信息图。将文章/笔记转化为手机可读的 HTML 信息图,自动匹配视觉风格。触发场景:文章转图、笔记转图、信息图、转小红书图、做张图、可视化这篇文章、文生图。</p>
</div>
<a rel="nofollow" href="/xiazai/skill7761" title="Article To Html" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
</th>
<td rowspan="2">课程名</td>`,然后“第3节”行的“周三”列不写任何单元格。<h3>用 `<tbody>` 封装全部课时行,保持结构语义化
所有具体节次内容(第1节、第2节……)都放在 `</tbody>
<tbody>` 里,每节是一行 `<tr>`:
- 每行第一个单元格是 `<th scope="row">第X节</th>`,其余为 `<td>`;
- 即使某时段没课,也要保留空 `</td>
<td>`,确保列数对齐;
- 不要把星期标题也塞进 `</td>
</tr>
</tbody>
<tbody>`,否则破坏语义,影响 CSS 定位和响应式处理;
- 可给 `<table>` 加 `class="timetable"` 方便后续统一控制边框、字体、高度等。
<p>好处:语义清晰,打印时 `<thead>` 自动每页重复;配合 CSS 可轻松实现隔行变色、悬停高亮、移动端隐藏节次列等效果。<h3>基础结构代码骨架(可直接复用)</h3>
<p>以下是最简但完整的二维结构模板:</p>
<pre class="brush:php;toolbar:false;"></pre>
<table class="timetable">
<thead><tr>
<th></th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
</tr></thead>
<tbody>
<tr>
<th scope="row">第1节</th>
<td></td>
<td>数学</td>
<td rowspan="2">物理实验</td>
<td></td>
<td>英语</td>
</tr>
<tr>
<th scope="row">第2节</th>
<td>语文</td>
<td></td>
<td></td>
<td>编程</td>
</tr>
</tbody>
</table>
</thead></p>
</table>
</tbody>
</h3>
</tr>
</tbody>
</h3>
</table>
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










