dmz社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 564|回复: 0

[Html/Css] HTML表格概念、语法、操作、案例

[复制链接]
  • TA的每日心情

    2024-2-20 11:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    878

    主题

    4343

    帖子

    3995

    积分

    终身会员[A]

    Rank: 7Rank: 7Rank: 7

    积分
    3995

    发表于 2020-3-29 09:00:02 | 显示全部楼层 |阅读模式

    本站资源全部免费,回复即可查看下载地址!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    创建两行三列表格
    [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>


    1888967-20200130142240010-1693782146.png

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




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



    表格属性

    1.png

    3.png



    [HTML] 纯文本查看 复制代码
    <!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>




    4.png
    tr标签属性


    5.png

    td和th标签属性
    6.png


    thead / tbody / tfoot 标签属性
    7.png

    跨列属性 colspan
    跨行属性 rowspan


    [HTML] 纯文本查看 复制代码
    <!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>



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


    [HTML] 纯文本查看 复制代码
    <!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>



    9.png



    2.png
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|小黑屋|本站代理|dmz社区

    GMT+8, 2025-2-2 04:35 , Processed in 0.125793 second(s), 36 queries .

    Powered by Discuz! X3.4 Licensed

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表