如何在 HTML 中建立表格標題?


在 HTML 中使用 <th> 標籤來建立標題。HTML <th> 標籤用於在表格中指定表頭單元格或表格標題。

以下是屬性:

屬性

描述
abbr
abbreviated_text
已棄用 - 指定表頭單元格中內容的縮寫版本。
align
right
left
center
justify
char
已棄用 - 表頭單元格中的內容對齊方式。
axis
Name
已棄用 - 為此 th 指定一個類別。
bgcolor
rgb(x,x,x)
#hexcode
colorname
已棄用 - 指定表頭單元格的背景顏色。
char
Character
已棄用 - 指定要對齊文字的字元。當 align = "char" 時使用。
charoff
畫素或 %
已棄用 - 指定相對於使用 char 屬性指定的第一個字元的對齊偏移量(以畫素或百分比值表示)。當 align = "char" 時使用。
colspan
數字
指定表頭單元格跨越的列數。
headers
Id
指定單元格關聯的一個或多個表頭單元格。
height
畫素
已棄用 - 指定表頭單元格的高度。
nowrap
Nowrap
已棄用 - 阻止文字自動換行。
rowspan
rowspan
指定表頭單元格跨越的行數。
scope
col
colgroup
row
rowgroup
此屬性用於表頭單元格,並指定將使用此表頭資訊的單元格。
valign
top
middle
bottom
baseline
已棄用 - 垂直對齊方式。
width
畫素或 %
已棄用 - 指定表頭單元格的寬度

示例

您可以嘗試執行以下程式碼來學習如何在 HTML 中建立表格標題:

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <h3>Result</h3>

      <table>
         <th>Marks</th>
         <th>Student</th>

         <tr>
            <td>600</td>
            <td>Amit</td>
         </tr>
         <tr>
            <td>400</td>
            <td>Anil</td>
         </tr>
      </table>

   </body>
</html>

更新於: 2020-03-02

607 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

立即開始
廣告