当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。