<table>標記
1.基本格式:<table 屬性1="屬性值1" 屬性2="屬性值2" ... ...>表格內容</table>
2.table標記的屬性
width屬性 表示表格的寬度,他的值可以是像素(px)也可以是父級元素的百分比(%)
height屬性 表示表格的高度,他的值可以是像素(px)也可以是父級元素的百分比(%)
border屬性 表示表格外邊框的寬度
align屬性 表格的顯示位置
值:
1.left居左顯示
2.center居中顯示
3.right居右顯示
默認值left
cellspacing屬性 單元格之間的間距,默認是2px,單位像素
cellpadding屬性 單元格內容與單元格邊框的顯示距離,單位像素
frame屬性
1.作用:控制表格邊框最外層的四條線框
2.屬性值:
void(默認值) 表示無邊框
above 表示僅頂部有邊框
below 表示僅有底部邊框
hsides 表示僅有頂部邊框和底部邊框
lhs 表示僅有左側邊框
rhs 表示僅有右側邊框
vsides 表示僅有左右側邊框
box 包含全部4個邊框
border 包含全部4個邊框
rules屬性
1.作用:控制是否顯示以及如何顯示單元格之間的分割線
2.屬性值:
none(默認值) 表示無分割線
all 表示包括所有分割線
rows 表示僅有行分割線
clos 表示僅有列分割線
groups 表示僅在行組和列組之間有分割線
<caption>標記
1.使用時候:表格需要標題的時候使用
2.正確使用:<caption>屬性的插入位置,直接位於<table>屬性之后,<tr>表格行之前
3.align屬性
top 標題放在表格的上部
bottom 標題放在表格的下部
left 標題放在表格的左部
right 標題放在表格的右部
<tr>標記
1.使用:定義表格的一行,對於每一個表格行,都是由一對<tr>...</tr>標記表示,每一行<tr>標記內可以嵌套多個<td>或者<th>標記
2.可選屬性:
bgcolor屬性:設置背景顏色
格式:bgcolor="顏色值"
align屬性:設置垂直方向對齊方式
格式:align="值"
值:
1.bottom 靠頂端對齊
2.top 靠底部對齊
3.middle 居中對齊
valign屬性:設置水平方向對齊方式
格式:valign="值"
值:
1.left 靠左對齊
2.right 靠右對齊
3.center 居中對齊
<td>和<th>
1.<td>和<th>都是單元格的標記,其必須嵌套在<tr>標簽內,是成對出現
2.兩者的區別:
<th>是表頭標記,通常位於首行或者首列,<th>中的文字默認會被加粗,而<td>不會
<td>是數據標記,表示該單元格的具體數據
3.共同之處:
兩者的標記屬性都是一樣的
4.屬性
bgcolor 設置單元格背景
align 設置單元格對齊方式
valign 設置單元格垂直對齊方式
width 設置單元格寬度
height 設置單元格高度
rowspan 設置單元格所占行數
colspan 設置單元格所占列數
<html> <head> <title>表格</title> <meta charset="utf-8"> </head> <body> <table width="960" height="250" border="1" align="center" cellpadding="10" rules="all"> <caption align="bottom">表格的標題</caption> <tr bgcolor="#ccc" align="center" valign="center"> <th bgcolor="red" align="left" rowspan="2" colspan="2">班級</th> <th>姓名</th> <th>年齡</th> <th>成績</th> </tr> <tr> <td>四年級一班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> <tr> <td>四年級一班</td> <td>李四</td> <td>14</td> <td>90</td> </tr> <tr> <td>四年級一班</td> <td>王五</td> <td>18</td> <td>50</td> </tr> </table> </body> </html>
<html> <head> <title>表格制作成績表</title> <meta charset="UTF-8"> </head> <body> <table width="960" align="center" border="1" rules="all" cellpadding="15"> <tr> <th>班級</th> <th>姓名</th> <th>年齡</th> <th>成績</th> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> <tr align="center"> <td>四年級1班</td> <td>李四</td> <td>13</td> <td>90</td> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> </table> <br/> <table width="960" align="center" border="1" rules="all" cellpadding="15"> <tr> <th>班級</th> <th>姓名</th> <th>年齡</th> <th>成績</th> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> <tr align="center"> <td>四年級1班</td> <td>李四</td> <td>13</td> <td bgcolor="#ccc"></td> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> </table> <br/> <table width="960" align="center" border="1" rules="all" cellpadding="15"> <tr bgcolor="#ccc"> <th>班級</th> <th>姓名</th> <th>年齡</th> <th>成績</th> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> <tr align="center"> <td>四年級1班</td> <td>李四</td> <td>13</td> <td bgcolor="red"><font color="white">53</font></td> </tr> <tr align="center"> <td>四年級1班</td> <td>張三</td> <td>16</td> <td>80</td> </tr> </table> </body> </html>
