HTML中如何为表格添加标题(添加的标题与表格相对静止)(<table><caption>标题</caption></table>)

<!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>之外不起作用。)


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值