表格结构:
<table> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> </table>
每一行单元格的数目必须一样
实例:
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>我的网页</title> 6 </head> 7 <body> 8 <table border="1"> 9 <tr> 10 <td> </td> 11 <td> </td> 12 <td> </td> 13 </tr> 14 <tr> 15 <td> </td> 16 <td> </td> 17 <td> </td> 18 </tr> 19 <tr> 20 <td> </td> 21 <td> </td> 22 <td> </td> 23 </tr> 24 </table> 25 </body> 26 </html>
常用属性:
border:边框的粗细
bordercolor:边框颜色
width:固定值或百分比
height:固定值或百分比
bgcolor:表格的背景颜色
background:背景图片
cellpadding:单元格边线到内容间的距离
cellspacing:单元格之间的距离
align:水平对齐方式
rules:合并单元格边框线 取值:all 兼容性不好,最好使用css
<tr>
常用属性:
bgcolor:
height:行高 没有width
align:文字水平居中
valign:垂直居中 取值:top middle bottom
实例:
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>我的网页</title> 6 </head> 7 <body> 8 <table border="1" width="500" rules="all" align="center"> 9 <tr height="100" align="center" valign="middle" bgcolor="#FF0000"> 10 <td>编号</td> 11 <td>姓名</td> 12 <td>性别</td> 13 <td>学历</td> 14 </tr> 15 <tr> 16 <td> </td> 17 <td> </td> 18 <td> </td> 19 <td> </td> 20 </tr> 21 <tr> 22 <td> </td> 23 <td> </td> 24 <td> </td> 25 <td> </td> 26 </tr> 27 <tr> 28 <td> </td> 29 <td> </td> 30 <td> </td> 31 <td> </td> 32 </tr> 33 <tr> 34 <td> </td> 35 <td> </td> 36 <td> </td> 37 <td> </td> 38 </tr> 39 <tr> 40 <td> </td> 41 <td> </td> 42 <td> </td> 43 <td> </td> 44 </tr> 45 </table> 46 </body> 47 </html>
<th>标题单元格 自动加粗居中
实例:
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>我的网页</title> 6 </head> 7 <body> 8 <table border="1" width="500" rules="all" align="center"> 9 <tr height="100"> 10 <th>编号</th> 11 <th>姓名</th> 12 <th>性别</th> 13 <th>学历</th> 14 </tr> 15 <tr> 16 <td> </td> 17 <td> </td> 18 <td> </td> 19 <td> </td> 20 </tr> 21 <tr> 22 <td> </td> 23 <td> </td> 24 <td> </td> 25 <td> </td> 26 </tr> 27 </table> 28 </body> 29 </html>
<td>或<th>
常用属性:
width:就是列宽
height:就是行高
bgcolor:
background:
align:
valign:
rowspan:上下合并单元格
colspan: 左右合并单元格
实例:
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>我的网页</title> 6 </head> 7 <body> 8 <table border="1" width="500" rules="all" align="center"> 9 <tr height="100"> 10 <th>编号</th> 11 <th>姓名</th> 12 <th>性别</th> 13 <th>学历</th> 14 </tr> 15 <tr> 16 <td> </td> 17 <td> </td> 18 <td> </td> 19 <td> </td> 20 </tr> 21 <tr> 22 <td colspan="4"> </td> 23 </tr> 24 <tr> 25 <td colspan="3"> </td> 26 <td> </td> 27 </tr> 28 <tr> 29 <td colspan="2"> </td> 30 <td> </td> 31 <td> </td> 32 </tr> 33 </table> 34 </body> 35 </html>
实例:
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>我的网页</title> 6 </head> 7 <body> 8 <table border="1" width="500" rules="all" align="center"> 9 <tr height="100"> 10 <th>编号</th> 11 <th>姓名</th> 12 <th>性别</th> 13 <th>学历</th> 14 </tr> 15 <tr> 16 <td rowspan="4"> </td> 17 <td> </td> 18 <td> </td> 19 <td> </td> 20 </tr> 21 <tr> 22 <td> </td> 23 <td> </td> 24 <td> </td> 25 26 </tr> 27 <tr> 28 <td> </td> 29 <td> </td> 30 <td> </td> 31 32 </tr> 33 <tr> 34 <td> </td> 35 <td> </td> 36 <td> </td> 37 38 </tr> 39 </table> 40 </body> 41 </html>
时间: 2024-12-31 03:49:58