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


HTML Legend align用法及代码示例


HTML DOM中的图例align属性用于设置或返回<legend>元素的align属性的值。

用法:

  • 它返回图例align属性。
    Legendobject.align;
  • 它设置图例对齐属性。
    Legendobject.align="left|right|top|bottom"

属性值:该属性接受上述和以下所述的四个参数:


  • left:它将标题设置在元素的左侧。
  • right:它将标题设置在元素的右侧。
  • top:它将标题设置为元素的顶部。
  • bottom:它将标题设置为元素的底部。

范例1:本示例返回图例align属性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>DOM Legend align Property</title> 
    <style> 
        form { 
            width:70%; 
        } 
          
        label { 
            display:inline-block; 
            float:left; 
            clear:left; 
            width:90px; 
            margin:5px; 
            text-align:left; 
        } 
          
        input[type="text"] { 
            width:250px; 
            margin:5px 0px; 
        } 
          
        .gfg { 
            font-size:40px; 
            color:green; 
            font-weight:bold; 
        } 
    </style> 
</head> 
  
<body> 
    <div class="gfg">GeeksforGeeks</div> 
    <h2>DOM Legend align Property</h2> 
    <form id="myGeeks"> 
        <fieldset> 
            <!-- Assigning legend id -->
            <legend id="GFG" align="left">STUDENT::</legend> 
            <label>Name:</label> 
            <input type="text"> 
            <br> 
            <label>Email:</label> 
            <input type="text"> 
            <br> 
            <label>Date of birth:</label> 
            <input type="text"> 
            <br> 
            <label>Address:</label> 
            <input type="text"> 
            <br> 
            <label>Enroll No:</label> 
            <input type="text"> 
        </fieldset> 
    </form> 
    <br> 
    <button onclick="myGeeks()">Submit</button> 
    <p id="sudo" style="font-size:25px;"></p> 
    <script> 
        function myGeeks() { 
  
            // Accessing legend tag  
            var g = 
                document.getElementById("GFG").align; 
  
            document.getElementById( 
                "sudo").innerHTML = g; 
        } 
    </script> 
</body> 
  
</html>

输出:

  • 在单击按钮之前:
  • 单击按钮后:

范例2:本示例设置图例align属性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>DOM Legend align Property</title> 
    <style> 
        form { 
            width:70%; 
        } 
          
        label { 
            display:inline-block; 
            float:left; 
            clear:left; 
            width:90px; 
            margin:5px; 
            text-align:left; 
        } 
          
        input[type="text"] { 
            width:250px; 
            margin:5px 0px; 
        } 
          
        .gfg { 
            font-size:40px; 
            color:green; 
            font-weight:bold; 
        } 
    </style> 
</head> 
  
<body> 
    <div class="gfg">GeeksforGeeks</div> 
    <h2>DOM Legend align Property</h2> 
    <form id="myGeeks"> 
        <fieldset> 
            <!-- Assigning legend id -->
            <legend id="GFG" align="left">STUDENT::</legend> 
            <label>Name:</label> 
            <input type="text"> 
            <br> 
            <label>Email:</label> 
            <input type="text"> 
            <br> 
            <label>Date of birth:</label> 
            <input type="text"> 
            <br> 
            <label>Address:</label> 
            <input type="text"> 
            <br> 
            <label>Enroll No:</label> 
            <input type="text"> 
        </fieldset> 
    </form> 
    <br> 
    <button onclick="myGeeks()">Submit</button> 
    <p id="sudo" style="font-size:25px;"></p> 
    <script> 
        function myGeeks() { 
  
            // Accessing legend tag  
            var g = 
                document.getElementById("GFG").align = "right"; 
  
            document.getElementById( 
                "sudo").innerHTML =  
              "The value of the align attribute was changed to " + g; 
        } 
    </script> 
</body> 
  
</html>

输出:

  • 在单击按钮之前:
  • 单击按钮后:

支持的浏览器:下面列出了HTML DOM图例align属性支持的浏览器:

  • 谷歌浏览器
  • IE浏览器
  • Firefox
  • Opera
  • Safari


相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML | DOM Legend align Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。