格標簽:
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>
格是頁面中常見的一中標簽,通常是用來數據展示的,而不是用來布局。
<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>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
格式化表格包括調整表格的樣式、布局和顏色等,以提高其可讀性和美觀性。
在HTML中,格式化通常通過CSS完成。
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
</style>
假設我們需要創建一個3x3的表格,顯示一個小型團隊的成員信息。
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 50%;
border-collapse: collapse;
margin: 25px 0;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Position</th>
<th>Email</th>
</tr>
<tr>
<td>Alice</td>
<td>Manager</td>
<td>alice@example.com</td>
</tr>
<tr>
<td>Bob</td>
<td>Developer</td>
<td>bob@example.com</td>
</tr>
<tr>
<td>Charlie</td>
<td>Designer</td>
<td>charlie@example.com</td>
</tr>
</table>
</body>
</html>
在這個HTML實例中,我們創建了一個帶有條紋效果的表格,表頭有綠色背景和白色文字,每個單元格都有適當的填充和邊框。
創建和格式化表格是一項基本技能,無論是在文檔編輯器還是HTML中。一個良好格式化的表格不僅能有效傳達信息,還能提升整體文檔或網頁的美觀性和專業性。通過實踐這些技巧和使用示例作為參考,你可以創建出既實用又吸引人的表格。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。