<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>表格的标题</title>
<base target="_self">
</head>
<body>
<!--最初的表格-->
<h3 align="center">表格的标题</h3>
<table border="1" cellspacing="2" cellpadding="2" width="300px" height="100px" align="center">
<tr>
<td>北京</td>
<td>上海</td>
</tr>
<tr>
<td>深圳</td>
<td>广州</td>
</tr>
</table>
<br><br><br><br>
<!--表格标题不改变位置,只改变表格的位置,观察标题是否一直和表格对齐-->
<h3 align="center">表格的标题</h3>
<table border="1" cellspacing="2" cellpadding="2" width="300px" height="100px" align="right">
<tr>
<td>北京</td>
<td>上海</td>
</tr>
<tr>
<td>深圳</td>
<td>广州</td>
</tr>
</table>
<br><br><br><br><br><br><br><br><br><br><br>
<!--正确的表格标题(标题一直和表格整体对齐,不论怎么改变表格位置,标题一直相对表格在原先的位置上)-->
<table border="1" width="300px" height="100px" align="center" cellspacing="2" cellpadding="2">
<caption><h3>表格的标题</h3></caption>
<tr>
<td>北京</td>
<td>上海</td>
</tr>
<tr>
<td>深圳</td>
<td>广州</td>
</tr>
</table>
</body>
</html>
添加表格标题的方法(标签):
<caption>标题内容</caption>(这对标签必须写在<table></table>之间才能起作用,写在<table></table>之外不起作用。)