HTML進階標籤之表格標籤,html表格標籤
前面學習了一下HTML的常用標籤, 今天開始進階標籤之路!
一.表格標籤
1.作用: 建立一張表格
2.各屬性作用:
<table cellspacing="0" cellpadding="0"></table> <!--表格標籤 cellspacing:單元格邊距. cellpadding: 單元格間距-->
<caption> </caption> <!--caption: 置於table內部,<tr>標籤之前, 未設定特定位置時, 會隨著表格的移動而移動 -->
<td colspan="1" rowpan="3"></td> <!--colspan: 規定單元格可橫跨的列數. rowpan: 規定單元格可橫跨的行數. 注意: 這兩種屬性使用時, 要將被合并的單元格刪除, 否則會出現單元格被擠出-->
<th></th> <!--與<td>標籤區別: 加粗置中-->
3.程式碼範例:
<!DOCTYPE html><html> <head> <title>表格的應用</title><meta charset="utf-8"> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <a href="Main.html">返回首頁</a> <!-- table: 表格標籤. cellspacing:儲存格邊距. cellpadding:儲存格間距 --> <table border="1" width="400" align="center" cellspacing="0" cellpadding="0"> <caption align="center"> <!-- caption: 置於table標籤內部, <tr>標籤之前, 未設定特定的位置時,會隨著表格的移動而移動 --> <h1>我的表格</h1> </caption> <tr> <th>編號</th> <!-- 與<td>標籤唯一不同: 加粗置中 --> <th>姓名</th> <th>性別</th> <th>職務</th> <th>手機</th> </tr> <tr> <td>1</td> <td>老大</td> <td>男</td> <td>董事長</td> <td>18910504201</td> </tr> <tr> <td>2</td> <td>老二</td> <td colspan="1" rowspan="3" align="center">女</td> <!-- colspan: 規定單元可橫跨的列數. rowspan: 規定儲存格可橫跨的行數, 這兩種屬性使用時, 要將被合并的儲存格刪除, 否則會出現單元 格被擠出 --> <td>總經理</td> <td>133111111111</td> </tr> <tr> <td>3</td> <td>老三</td> <td colspan="1" rowspan="2" align="center">副總</td> <td>13322222222</td> </tr> <tr> <td>4</td> <td>老四</td> <td>13333333333</td> </tr> <tr> <td>5</td> <td>老五</td> <td>男</td> <td>總監</td> <td>13344444444</td> </tr> </table> </body></html>
4.運行結果