HTML基礎知識——表格標籤

table表格

table表示一個表格區域
caption表示表格的標題
tr表示一行
th表示表格的列名(即通常的表格第一行用th,儘量少用)
td表示表格內一個單元格內的內容
示例:

<table bgcolor="red" align="center" border="1">
        <caption>培訓人員名單</caption>
        <tr>
            <th>名字</th>
            <th>專業</th>
            <th>年齡</th>
            <th>狀態</th>
        </tr><br>
        <tr>
            <td>張三</td>
            <td>JAVA</td>
            <td>22</td>
            <td>在學</td>
        </tr><br>
        <tr>
            <td>李四</td>
            <td>web</td>
            <td>28</td>
            <td>休學</td>
        </tr>
    </table>

效果爲
在這裏插入圖片描述

在每一個table中,可以存在子table
tr、td中不可以嵌套子tr、td

table中常用屬性:
border=邊框的厚度(0表示沒有邊框,數字表示邊框厚度像素)
bordercolor=邊框顏色
bgcolor=表格背景顏色
cellspacing=指定了單元格的間距 (0則爲無間隔邊框)
width:表格總寬度(佔網頁的百分比或使用像素,加單位px)
hight:表格總高度(佔網頁的百分比或使用像素,加單位px)
background:表格的背景圖
【註釋:dp表示字體單位,px是像素單位、行列、像素都容易出現錯位問題】
tr常用屬性:
height = 高度值
bgcolor=行背景顏色
bordercolor=行邊框顏色
align=(left right center)
valign=(top middle bottom baseline)
rowspan=‘2’(這個單元格佔兩行)
colspan=‘2’(這個單元格佔2列)

運用屬性的示例:

<table align="center" border="1" bordercolor="red" width="100%" cellspacing="0" cellpadding="10" background="./test2.png">
        <caption>培訓人員名單</caption>
        <tr bgcolor="#0F2347">
            <th>名字</th>
            <th>專業</th>
            <th>年齡</th>
            <th>狀態</th>
        </tr><br>
        <tr align="center" >
            <td align="center">張三</td>
            <td>JAVA</td>
            <td>22</td>
            <td>在學</td>
        </tr><br>
        <tr>
            <td>李四</td>
            <td>web</td>
            <td>28</td>
            <td>休學</td>
        </tr>
    </table>

效果:

發佈了12 篇原創文章 · 獲贊 5 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章