HTML中的<table>

table的作用

<table>: 定義HTML文檔中的表格

table的元素

<caption>標(biāo)簽給表格設(shè)置標(biāo)題
<thead>標(biāo)簽定義表格的頁頭
<tr>定義表格中的一行
<th>定義表格中的表頭
<td>定義表格中的一列
<tbody>標(biāo)簽定義表格的主體
<tfoot>標(biāo)簽定義表格的頁腳

舉例應(yīng)用:

<table border="1">
<caption>學(xué)生信息</caption>
    <thead>
        <tr>
            <th>姓名</th>
            <th>年齡</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>張三</td>
            <td>25</td>
        </tr>
        <tr>
            <td>李四</td>
            <td>23</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>平均</td>
            <td>24</td>
        </tr>
    </tfoot>
</table>

運(yùn)行結(jié)果為:

擴(kuò)展

  • <colgroup>標(biāo)簽
    可以對(duì)表格的列進(jìn)行組合,從而進(jìn)行整體格式化。
    舉例:
<head>
    <style>
        #colgroup1 {
            background-color: red
        }
        #colgroup2 {
            background-color: green;
        }
    </style>
</head>
<body>
    <table border="1">
        <colgroup id="colgroup1" span="1">
            <colgroup id="colgroup2" span="1">
                <thead>
                    <tr>
                        <th id="name">姓名</th>
                        <th id="age">年齡</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td headers="name one">張三</td>
                        <td headers="age one">25</td>
                    </tr>
                    <tr>
                        <td headers="name two">李四</td>
                        <td headers="age two">23</td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td>平均</td>
                        <td>24</td>
                    </tr>
                </tfoot>
    </table>
</body>

則顯示結(jié)果為:

  • td的colspan屬性
    設(shè)置表格的占用標(biāo)準(zhǔn)表格的幾列
    舉例:
<table border="1">
    <thead>
        <tr>
            <th>姓名</th>
            <th>年齡</th>
            <th>成績</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>張三</td>
            <td colspan="2">25</td>
        </tr>
        <tr>
            <td>李四</td>
            <td>23</td>
            <td>56</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>平均</td>
            <td>24</td>
            <td>80</td>
        </tr>
    </tfoot>
</table>

運(yùn)行結(jié)果為:

  • td的rowspan屬性
    設(shè)置表格的占用標(biāo)準(zhǔn)表格的幾行
    舉例:
<table border="1">
    <thead>
        <tr>
            <th>姓名</th>
            <th>年齡</th>
            <th>成績</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>張三</td>
            <td>25</td>
            <td rowspan="2">90</td>
        </tr>
        <tr>
            <td>李四</td>
            <td>23</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>平均</td>
            <td>24</td>
            <td>80</td>
        </tr>
    </tfoot>
</table>

運(yùn)行結(jié)果為:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,626評(píng)論 18 399
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 3,995評(píng)論 0 11
  • 前端07班 王 對(duì)于table的使用我們會(huì)有種先入為主的厭惡。覺得頁面中不應(yīng)該出現(xiàn)表格!其實(shí)這只是針對(duì)使用HTML...
    ea203453e188閱讀 2,805評(píng)論 0 5
  • 形象的內(nèi)容寬廣而豐富,它包括你的穿著、言行、舉止、修養(yǎng)、生活方式、知識(shí)層次、家庭出身、你住在哪里、開什么車、和什么...
    peter_621f閱讀 208評(píng)論 0 0
  • 加入讀書會(huì)也有一年的時(shí)間了,參加讀書會(huì)的線下活動(dòng)其實(shí)并不多,原因很簡單,我覺得自己讀書少,不敢去讀書人面前得瑟! ...
    眸眸小白閱讀 321評(píng)論 2 0

友情鏈接更多精彩內(nèi)容