HTML - span 屬性



HTML span 屬性用於指定<col><colgroup> 元素應跨越的列數。

span 屬性用於跨越列,當我們對<col><colgroup> 元素應用 CSS 屬性時,span 允許我們將相同的 CSS 屬性應用於多個列。

語法

<tag span="2">

應用於

以下列出的元素允許使用 HTML span 屬性。

元素 描述
<colgroup> HTML <colgroup> 標籤用於描述表格中一列或多列的集合,用於格式化。
<col> HTML <col> 標籤用於提供有關列的資訊。

HTML span 屬性示例

以下示例將說明 HTML span 屬性,以及我們應該在哪裡以及如何使用此屬性!

在 <colgroup> 元素上實現背景顏色

在以下示例中,我們將使用 span 屬性透過一次選擇使用 <colgroup> 的列來設定前三列的背景顏色。

<!DOCTYPE html>
<html>

<head>
      <!-- Used to set the border on the table -->
      <style>
         table,
         th,
         td {
            border: 1px solid gray;
         }
      </style>
</head>

<body>
      <h3>HRML span Attribute</h3>
      <table>
         <colgroup span="3" 
                   style="background:green">
         </colgroup>
         <tr>
            <th>Course</th>
            <th>Enroll Date</th>
            <th>Status</th>
            <th>Certificate</th>
         </tr>
         <tr>
            <td>HTML</td>
            <td>30th May</td>
            <td>Learning</td>
            <td>Not Issued</td>
         </tr>
         <tr>
            <td>CSS</td>
            <td>31st May</td>
            <td>Learning</td>
            <td>Not Issued</td>
         </tr>
      </table>
</body>

</html>

在 <col> 元素上實現背景顏色

在以下示例中,我們將使用 span 屬性透過分別選擇使用 <col> 的列來設定前兩列的背景顏色。

<!DOCTYPE html>
<html>

<head>
      <!-- Used to set the border on the table -->
      <style>
         table,
         th,
         td {
            border: 1px solid gray;
         }
      </style>
</head>

<body>
      <h3>HRML span Attribute</h3>
      <table>
         <colgroup> 
            <col span="2" style="background-color:green"> 
            <col style="background-color:yellow">
        </colgroup>
         <tr>
            <th>Course</th>
            <th>Enroll Date</th>
            <th>Status</th>
            <th>Certificate</th>
         </tr>
         <tr>
            <td>HTML</td>
            <td>30th May</td>
            <td>Learning</td>
            <td>Not Issued</td>
         </tr>
         <tr>
            <td>CSS</td>
            <td>31st May</td>
            <td>Learning</td>
            <td>Not Issued</td>
         </tr>
      </table>
</body>

</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
span
html_attributes_reference.htm
廣告

© . All rights reserved.