html 表格是一種將數據組織成網格狀結構的工具,由行和列組成。創建表格需要使用 標簽,其中 和 分別表示表頭和表身, 表示行, 和 分別表示表頭和表身單元格。表格可以設置邊框、間距和寬度。
HTML 表格的使用
什么是 HTML 表格?
HTML 表格用于將數據組織成網格狀結構,每格稱為一個單元格。表格由行和列組成,行是水平的,而列是垂直的。
如何創建 HTML 表格
要在 HTML 中創建表格,需要使用 <table> 標簽:<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="html"><table>
<thead><tr>
<th>列標題 1</th>
<th>列標題 2</th>
</tr></thead>
<tbody>
<tr>
<td>單元格 1</td>
<td>單元格 2</td>
</tr>
<tr>
<td>單元格 3</td>
<td>單元格 4</td>
</tr>
</tbody>
</table></code></pre><div class="contentsignin">登錄后復制</div></div>
<ul><li><code><thead> 和 <code><tbody> 分別表示表頭和表身。<li><code><tr> 表示行。<li><code><th> 表示表頭單元格。<li><code><td> 表示表身單元格。<p><strong>表格屬性</strong></p>
<ul>
<li>
<strong>border:</strong> 控制表格邊框的粗細。</li>
<li>
<strong>cel<a style="color:#f60; text-decoration:underline;" href="https://www.php.cn/zt/79544.html" target="_blank">lsp</a>acing:</strong> 設置單元格之間的垂直間距。</li>
<li>
<strong>cellpadding:</strong> 設置單元格內元素與單元格邊框之間的間距。</li>
<li>
<strong>width:</strong> 指定表格的寬度。</li>
</ul>
<p><strong>表頭和表身</strong></p>
<ul><li><strong>表頭(<thead>): 包含表格中標題或列標簽。<li><strong>表身(<tbody>): 包含表格中的實際數據。<p><strong>單元格屬性</strong></p>
<ul>
<li>
<strong>colspan:</strong> 指定單元格跨越的列數。</li>
<li>
<strong>rowspan:</strong> 指定單元格跨越的行數。</li>
<li>
<strong>align:</strong> 指定單元格內文本的對齊方式。</li>
</ul>
<p><strong>實例</strong></p>
<p>以下是一個帶有邊框和內邊距的簡單表格:</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="html"><table border="1" cellpadding="5">
<tr>
<th>姓名</th>
<th>年齡</th>
</tr>
<tr>
<td>張三</td>
<td>20</td>
</tr>
<tr>
<td>李四</td>
<td>25</td>
</tr>
</table></code></pre><div class="contentsignin">登錄后復制</div></div>
</tbody></strong></li>
</thead></strong></li></ul>
</td>