html 表格是一種將數(shù)據(jù)組織成網(wǎng)格狀結(jié)構(gòu)的工具,由行和列組成。創(chuàng)建表格需要使用 標(biāo)簽,其中 和 分別表示表頭和表身, 表示行, 和 分別表示表頭和表身單元格。表格可以設(shè)置邊框、間距和寬度。
HTML 表格的使用
什么是 HTML 表格?
HTML 表格用于將數(shù)據(jù)組織成網(wǎng)格狀結(jié)構(gòu),每格稱為一個單元格。表格由行和列組成,行是水平的,而列是垂直的。
如何創(chuàng)建 HTML 表格
要在 HTML 中創(chuàng)建表格,需要使用 <table> 標(biāo)簽:<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="html"><table>
<thead><tr>
<th>列標(biāo)題 1</th>
<th>列標(biāo)題 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">登錄后復(fù)制</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> 控制表格邊框的粗細(xì)。</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> 設(shè)置單元格之間的垂直間距。</li>
<li>
<strong>cellpadding:</strong> 設(shè)置單元格內(nèi)元素與單元格邊框之間的間距。</li>
<li>
<strong>width:</strong> 指定表格的寬度。</li>
</ul>
<p><strong>表頭和表身</strong></p>
<ul><li><strong>表頭(<thead>): 包含表格中標(biāo)題或列標(biāo)簽。<li><strong>表身(<tbody>): 包含表格中的實(shí)際數(shù)據(jù)。<p><strong>單元格屬性</strong></p>
<ul>
<li>
<strong>colspan:</strong> 指定單元格跨越的列數(shù)。</li>
<li>
<strong>rowspan:</strong> 指定單元格跨越的行數(shù)。</li>
<li>
<strong>align:</strong> 指定單元格內(nèi)文本的對齊方式。</li>
</ul>
<p><strong>實(shí)例</strong></p>
<p>以下是一個帶有邊框和內(nèi)邊距的簡單表格:</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">登錄后復(fù)制</div></div>
</tbody></strong></li>
</thead></strong></li></ul>
</td>