當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


HTML <caption> align屬性用法及代碼示例


HTML <caption> align屬性用於指定<caption>元素的對齊方式。用於將標題與表格的左,右,頂部和底部對齊。 HTML5不支持此屬性。

用法:

<caption align="left | right | top | bottom> 

屬性值


  • left:它設置表的left-align標題。
  • right:它設置表的right-align標題
  • Top:它設置表的top-align標題。
  • Bottom:它設置表的bottom-align標題。

例:

<!-- HTML code to show the working of caption tag -->
<!DOCTYPE html> 
<html> 
  
<head> 
    <style> 
        table, 
        th, 
        td { 
            border:1px solid black; 
        } 
          
        #GFG { 
            font-size:25px; 
            color:green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1 style="color:green;font-size:35px;">  
    GeeksForGeeks  
    </h1> 
    <h2>HTML Caption align  Attribute</h2> 
  
    <table> 
        <!-- Adding caption to the table -->
        <caption id="GFG"
                 align="top"> 
          Students 
      </caption> 
        <tr> 
            <th>Firstname</th> 
            <th>Lastname</th> 
            <th>Age</th> 
        </tr> 
        <tr> 
            <td>Priya</td> 
            <td>Sharma</td> 
            <td>24</td> 
        </tr> 
        <tr> 
            <td>Arun</td> 
            <td>Singh</td> 
            <td>32</td> 
        </tr> 
        <tr> 
            <td>Sam</td> 
            <td>Watson</td> 
            <td>41</td> 
        </tr> 
    </table> 
<br> 
<br> 
    <table> 
        <!-- Adding caption to the table -->
        <caption id="GFG"
                 align="bottom"> 
          Students 
      </caption> 
        <tr> 
            <th>Firstname</th> 
            <th>Lastname</th> 
            <th>Age</th> 
        </tr> 
        <tr> 
            <td>Priya</td> 
            <td>Sharma</td> 
            <td>24</td> 
        </tr> 
        <tr> 
            <td>Arun</td> 
            <td>Singh</td> 
            <td>32</td> 
        </tr> 
        <tr> 
            <td>Sam</td> 
            <td>Watson</td> 
            <td>41</td> 
        </tr> 
    </table> 
</body> 
  
</html>

輸出:

支持的瀏覽器:下麵列出了HTML <caption> align屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • Firefox
  • 蘋果Safari
  • Opera


相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | <caption> align Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。