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


HTML Style minHeight用法及代碼示例


HTML DOM中的minHeight屬性用於設置或返回元素的最小高度。此屬性僅影響block-level元素,絕對或固定位置元素。

用法:

  • 它返回minHeight屬性。
    object.style.minHeight
  • 它用於設置minHeight屬性。
    object.style.minHeight = "length|%|initial|inherit"

屬性值:


描述
length 以長度單位定義長度。
定義與父元素相比的長度百分比
initial 設置默認的初始值。
inherit 從父元素繼承屬性。

返回值:它返回元素的最小高度。

範例1:

<!DOCTYPE html>  
<html>  
    <head>  
        <title> 
            DOM Style minHeight Property  
        </title>  
          
        <style> 
            #Geek1 { 
                color:white; 
                width:50%; 
                background:green; 
            } 
        </style> 
    </head>  
      
      
    <body>  
        <center>  
            <h1 id = "Geek1">  
                GeeksForGeeks  
            </h1>  
              
            <h2>DOM Style minHeight Property </h2>          
            <br>  
            <button type = "button" onclick = "geeks()">  
                Click to change  
            </button>  
              
            <script>  
                function geeks() {  
                    document.getElementById("Geek1").style.minHeight 
                            = "150px";  
                }  
            </script>  
        </center>  
    </body>  
</html>                             

輸出:

  • 在單擊按鈕之前:
  • 單擊按鈕後:

範例2:

<!DOCTYPE html>  
<html>  
    <head>  
        <title> 
            DOM Style minHeight Property 
        </title>  
          
        <style> 
            #Geek1 { 
                color:white; 
                width:50%; 
                background:green; 
            } 
            #Geek_Center { 
                background:yellow; 
                height:200px; 
            } 
        </style> 
    </head>  
      
    <body>  
        <center id = "Geek_Center">  
          
            <h1 id = "Geek1">  
                GeeksForGeeks  
            </h1>  
              
            <h2>DOM Style minHeight Property </h2>          
            <br>  
            <button type = "button" onclick = "geeks()">  
                Click to change  
            </button>  
              
            <script>  
                function geeks() {  
                    document.getElementById("Geek1").style.minHeight 
                            = "50%";  
                }  
            </script>  
        </center>  
    </body>  
</html>                                 

輸出:

  • 在單擊按鈕之前:
  • 單擊按鈕後:

支持的瀏覽器:下麵列出了DOM Style minHeight屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • 火狐瀏覽器
  • Opera
  • Safari


相關用法


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