打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
HTML表格概念、语法、操作、案例

创建两行三列表格

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    <table border="1">        <tr>            <td>2018年</td>            <td>2019年</td>            <td>2020年</td>        </tr>        <tr>            <td>8000</td>            <td>10000</td>            <td>120000</td>        </tr>    </table></body></html>

 

 

表格
th 表头,内容居中,加粗显示
<caption></caption> 表格标题,居中显示


 

表格作为整体被解析,完全解析完才会被显示出来
表格结构标签可以优化显示,加载一部分显示一部分
thead 表格的头(表头)
tbody 表格的主体(数据)
tfoot 表格的脚(脚注)


 

表格属性

 

 

 

 

 

 

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    <table border="1" width="500px" bgcolor="#f2f2f2" cellspacing="0" cellpadding="5px" align="center" frame="box" rules="rows">        <caption>前端工程师平均工资</caption>        <thead>            <tr>                <th>城市</th>                <th>2018年</th>                <th>2018年</th>                <th>2019年</th>                <th>2020年</th>            </tr>            <tr>                <th>城市</th>                <th>上半年</th>                <th>下半年</th>                <th>2019年</th>                <th>2020年</th>            </tr>        </thead>        <tbody>            <tr>                <td>北京</td>                <td>8000</td>                <td>9000</td>                <td>10000</td>                <td>120000</td>            </tr>            <tr>                <td>上海</td>                <td>6000</td>                <td>7000</td>                <td>8000</td>                <td>100000</td>            </tr>        </tbody>        <tfoot>            <tr>                <td>合计</td>                <td>7000</td>                <td>8000</td>                <td>9000</td>                <td>110000</td>            </tr>        </tfoot>    </table></body></html>

 

 tr标签属性

 

 td和th标签属性

 

 thead / tbody / tfoot 标签属性

 

 

跨列属性 colspan
跨行属性 rowspan

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    <table border="1" width="500px" bgcolor="#f2f2f2" cellspacing="0" cellpadding="5px" align="center" frame="box" rules="all">        <caption>前端工程师平均工资</caption>        <thead>            <tr bgcolor="#d8e4bc">                <th rowspan="2">城市</th>                <th colspan="2">2018年</th>                <th rowspan="2">2019年</th>                <th rowspan="2">2020年</th>            </tr>            <tr bgcolor="#d8e4bc">                                <th>上半年</th>                <th>下半年</th>            </tr>        </thead>        <tbody align="center" valign="middle">            <tr>                <td bgcolor="#b8cce4">北京</td>                <td>8000</td>                <td>9000</td>                <td>10000</td>                <td>12000</td>            </tr>            <tr>                <td bgcolor="#b8cce4">上海</td>                <td>6000</td>                <td>7000</td>                <td>8000</td>                <td>10000</td>            </tr>        </tbody>        <tfoot>            <tr align="center">                <td bgcolor="#b8cce4">合计</td>                <td>7000</td>                <td>8000</td>                <td>9000</td>                <td>11000</td>            </tr>        </tfoot>    </table></body></html>

 

 

表格嵌套:
嵌入的必须是完整的表格结构
放到td标签中

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    <table border="1" width="500px" bgcolor="#f2f2f2" cellspacing="0" cellpadding="5px" align="center" frame="box" rules="all">        <caption>前端工程师平均工资</caption>        <thead>            <tr bgcolor="#d8e4bc">                <th>城市</th>                <th>2018年</th>                <th>2019年</th>                <th>2020年</th>            </tr>        </thead>        <tbody align="center" valign="middle">            <tr>                <td bgcolor="#b8cce4">北京</td>                <td>                    <table border="1" cellspacing="0" frame="void">                        <tr>                            <td>上半年</td>                            <td>下半年</td>                        </tr>                        <tr>                            <td>8000</td>                            <td>9000</td>                        </tr>                    </table>                </td>                <td>10000</td>                <td>12000</td>            </tr>        </tbody>    </table></body></html>

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
表格属性设置
【引用】博客装饰-表格(2)
Bootstrap之表格checkbox复选框全选
重新发现HTML表格 | CSS | 前端观察
HTML表标题标签的定义与用法
小书匠语法说明之表格 | 小书匠
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服