HTML表格
一、课堂笔记
表格也就是数据展示的一个列表选项,一般会用来进行数据的一个展示
code:200,
msg:"查询成功",
data:[
{id:1,imgs:"https://001.jpg"}
]
拿到数据会进行页面的一个渲染工作,就需要有表格的出现
<table>
<thead>标题头</thead>
<tbody>内容区域</tbody>
<tfoot>底部</tfoot>
</table>
tr 就是行
td 就是列
th 就是表头
<table border="1" width="700px" align="center" cellspacing="1" style="text-align: center;">
<thead>
<tr>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
</tr>
</thead>
<tbody>
<tr>
<td>语文课</td>
<td>语文课</td>
<td>语文课</td>
<td>语文课</td>
<td>语文课</td>
</tr>
<tr>
<td>数学课</td>
<td>数学课</td>
<td>数学课</td>
<td>数学课</td>
<td>数学课</td>
</tr>
<tr>
<td>英语课</td>
<td>英语课</td>
<td>英语课</td>
<td>英语课</td>
<td>英语课</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
</tr>
</tfoot>
</table>
cellspacing:就是单元格和单元格之间的间距
我们需要面对不同的一个变化,需要对表格进行一个合并
合并分为二种
- 行合并:就是行与行之间的一个合并
colspan
- 列合并:就是列与列之间的一个合并
rowspan
<table border="1" width="700px" align="center" cellspacing="1" style="text-align: center;">
<thead>
<tr>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">语文课</td>
<td colspan="2">语文课</td>
</tr>
<tr>
<td rowspan="2">数学课</td>
<td>数学课</td>
<td>数学课</td>
<td>数学课</td>
<td>数学课</td>
</tr>
<tr>
<td>英语课</td>
<td>英语课</td>
<td>英语课</td>
<td>英语课</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
<td>晚上吃饭饭</td>
</tr>
</tfoot>
</table>
二、课后练习
利用课堂所学知识实现如下效果
设计思路:
将页面整体按表格设计,分为20行6列,前4行如图所示
图片1 | 名称 | 日期 | 图片2 | 名称 | 日期 |
---|---|---|---|---|---|
饰演 | 姓名 | 饰演 | 姓名 | ||
导演 | 姓名 | 导演 | 姓名 | ||
主演 | 姓名 | 主演 | 姓名 |
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.dir{
height: 1px;
opacity:0.3;
background-color: black;
}
</style>
</head>
<body>
<h3>参演电视剧</h3>
<table border="0" width="700px" height="80" cellspacing="0">
<tr>
<th rowspan="4"><img src="../imgs/1.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">县委大院</font></th>
<th><font size="2" >2002-12-7</font></th>
<th rowspan="4"><img src="../imgs/2.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">完美伴侣</font></th>
<th><font size="2" >2002-12-7</font></th>
<th></th>
</tr>
<tr>
<td><font size="2" >饰演</font></td>
<td><font size="2" color="#00a7d0">梅晓歌</font></td>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">保安</font></td>
</tr>
<tr>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">孔笙、毛珺琳、王宏</font></td>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">林玉芬、梁胜权</font></td>
</tr>
<tr>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
<br>
<table border="0" width="700px" height="80" cellspacing="0">
<tr>
<th rowspan="4"><img src="../imgs/3.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">繁花</font></th>
<th><font size="2" >2002-12-7</font></th>
<th rowspan="4"><img src="../imgs/4.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">猎场</font></th>
<th><font size="2" >2002-12-7</font></th>
<th></th>
</tr>
<tr>
<td><font size="2" >饰演</font></td>
<td><font size="2" color="#00a7d0">梅晓歌</font></td>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">保安</font></td>
</tr>
<tr>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">孔笙、毛珺琳、王宏</font></td>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">林玉芬、梁胜权</font></td>
</tr>
<tr>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
<br>
<table border="0" width="700px" height="80" cellspacing="0">
<tr>
<th rowspan="4"><img src="../imgs/5.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">外科风云</font></th>
<th><font size="2" >2002-12-7</font></th>
<th rowspan="4"><img src="../imgs/6.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">旋风十一人</font></th>
<th><font size="2" >2002-12-7</font></th>
<th></th>
</tr>
<tr>
<td><font size="2" >饰演</font></td>
<td><font size="2" color="#00a7d0">梅晓歌</font></td>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">保安</font></td>
</tr>
<tr>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">孔笙、毛珺琳、王宏</font></td>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">林玉芬、梁胜权</font></td>
</tr>
<tr>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
<br>
<table border="0" width="700px" height="80" cellspacing="0">
<tr>
<th rowspan="4"><img src="../imgs/7.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">大好时光</font></th>
<th><font size="2" >2002-12-7</font></th>
<th rowspan="4"><img src="../imgs/8.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">琅琊榜</font></th>
<th><font size="2" >2002-12-7</font></th>
<th></th>
</tr>
<tr>
<td><font size="2" >饰演</font></td>
<td><font size="2" color="#00a7d0">梅晓歌</font></td>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">保安</font></td>
</tr>
<tr>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">孔笙、毛珺琳、王宏</font></td>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">林玉芬、梁胜权</font></td>
</tr>
<tr>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
<br>
<table border="0" width="700px" height="80" cellspacing="0">
<tr>
<th rowspan="4"><img src="../imgs/9.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">伪装者</font></th>
<th><font size="2">2002-12-7</font></th>
<th rowspan="4"><img src="../imgs/10.jpg" alt="" width="60px" height="90px" ></th>
<th><font size="3" color="#00a7d0">四十九日*祭</font></th>
<th><font size="2">2002-12-7</font></th>
<th></th>
</tr>
<tr>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">梅晓歌</font></td>
<td><font size="2">饰演</font></td>
<td><font size="2" color="#00a7d0">保安</font></td>
</tr>
<tr>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">孔笙、毛珺琳、王宏</font></td>
<td><font size="2" >导演</font></td>
<td><font size="2" color="#00a7d0">林玉芬、梁胜权</font></td>
</tr>
<tr>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
</body>
</html>
完成效果
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">吴越,张新成、黄磊、李光洁</font></td>
<td><font size="2" >主演</font></td>
<td><font size="2" color="#00a7d0">高圆圆、张鲁一、张耀庆、王真儿</font></td>
</tr>
</table>
<div class="dir"></div>
~~~