表格标签
<table> <caption>表格标题</caption> <tr> <th>表头内容</th> </tr> <tr> <td>表格主体</td> </tr> </table>
复制代码
<caption></caption>是表格标题标签,可以不写(没有名字的表格)
<tr></tr> 表格中的一行
<th></th>表格中的表头(如表格中的“班级”、“姓名”字样,可以不写)
<td></td>正常的单元格(可以理解为“列”)
表格属性
<table border="1" cellspacing="0" cellpadding="10" bgcolor="skyblue" borderColor="red" align="center" width="500"> </table>
复制代码
border=“1” 表格的边框,单位为 px,可以不写单位
cellspacing=“0” 单元格和单元格之间的距离
cellpadding=“10” 内边距(内容与边框之间的距离)
bgcolor=“skyblue” 表格背景颜色,作用于整个表格(写在 tr 中时,作用在写定的那一行)
bordercolor=”red“ 边框颜色
align=”center“ 表格居中(写在某一个 tr 中时,写定的那一行内容居中)
width=”500“ 表格宽度,单位 px,可以不写单位(写在某一列时,表格整体宽度等于单元格宽度*单元格个数)
rowspan=”4“ 行合并,从第一个要合并的单元格开始计算个数
colspan=”4“ 列合并,从第一个要合并的单元格开始计算个数
示例代码
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body> <table border="1" cellspacing="0" cellpadding="10" bgcolor="yellow" borderColor="red" align="center" width="500"> <caption>班级信息统计表</caption> <tr> <th width="100">序号</th> <th width="100">姓名</th> <th width="100">班级</th> <th width="100">电话</th> <th width="100">性别</th> </tr> <tr bgcolor="skyblue" align="center"> <td rowspan="4">1</td> <td>张三</td> <td>三班</td> <td>8593</td> <td>男</td> </tr> <tr align="center"> <td>张三</td> <td>三班</td> <td>8593</td> <td>男</td> </tr> <tr align="center"> <td>张三</td> <td>三班</td> <td>8593</td> <td>男</td> </tr> <tr align="center"> <td>张三</td> <td>三班</td> <td>8593</td> <td>男</td> </tr> <tr> <td>备注:</td> <td colspan="4"></td> </tr> </table></body></html>
复制代码
结果如下
评论