5行CSS樣式碼,讓你的表格更加漂亮,先放最終效果:
最終樣式
<table class="style-table">
<thead>
<tr>
<th>序號</th>
<th>物品名稱</th>
<th>金額</th>
<th>備注</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>洗衣粉</td>
<td>15.00</td>
<td>自己用</td>
</tr>
<tr class="active-row">
<td>2</td>
<td>潔爾陰</td>
<td>25.00</td>
<td>老婆用</td>
</tr>
<tr >
<td>3</td>
<td>搓衣板</td>
<td>5.00</td>
<td>自己用</td>
</tr>
</tbody>
</table>
格是頁面中常見的一中標簽,通常是用來數據展示的,而不是用來布局。
<table>
<tr>
<td>單元格內的文字</td>
...
</tr>
...
</table>
設置表格的外觀樣式
<table border=1>
<tr>
<th>姓名</th>
<th>性別</th>
<th>電話</th>
</tr>
<tr>
<th>張三</th>
<td>女</td>
<td>18611110000</td>
</tr>
<tr>
<th>李四</th>
<td>男</td>
<td>18711110000</td>
</tr>
<tr>
<th>王五</th>
<td>男</td>
<td>18811110000</td>
</tr>
</table>
表格標題標簽,為表格添加標題,跟隨表格的位置而移動。設置標題,我們用的是caption標簽。
<table border="1">
<caption style="text-align:left">My savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>0</td>
</tr>
</table>
將標題定位在表格的左|右|上|下位置。
跨行合并 rowspan=“合并單元格的個數”
跨列合并 colspan=“合并單元格的個數”
合并順序:先上后下,先左后右
...
姓名 | 張三 | 性別 | 李四 | 照片 |
家庭住址 | 張三 | 性別 | 李四 | 照片 |
```
(1)先確定是跨行還是跨列合并
(2)根據先上后下,先左后右的原則,找到目標單元格,寫上合并方式(rowspan/colspan)和要合并的單元格數量
(3)刪除多余的單元格
表格的結構劃分,使用thead、tbody 、tfoot 三種標簽
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>0</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>0</td>
</tr>
<tr>
<td>February</td>
<td></td>
</tr>
</tbody>
</table>
(1) 元素內部必須包含一個或者多個 標簽。
(2) thead, tbody, 和 tfoot 元素默認不會影響表格的布局。用途主要是可以使用 CSS 來為這些元素定義樣式,從而改變表格的外觀。
格標簽:
table 表格標簽
熟悉表格常用的單詞:
border 邊距,align 格式 :‘ center’ 對齊,cellspacing 單元格與單元格的距離,cellpadding 單元格與內容的距離,wedth 寬度,height 高度,tr 表示:行,th 表示:表頭,td :表示列
編輯表格:
生成表格:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表格標簽</title>
</head>
<body>
<table border="" cellspacing="" cellpadding="">
<tr>
<th>姓名</th>
<th>性別</th>
<th>年齡</th>
</tr>
<tr>
<td>張三</td>
<td>男</td>
<td>18</td>
</tr>
<tr>
<td>李四</td>
<td>男</td>
<td>19</td>
</tr>
<tr>
<td>王五</td>
<td>男</td>
<td>20</td>
</tr>
</table>
</table>
</body>
</html>
*請認真填寫需求信息,我們會在24小時內與您取得聯系。