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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。