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


CSS height屬性用法及代碼示例


height屬性用於設置元素的高度。 height屬性不包含元素的邊距,邊距和邊框。

用法:

height:auto|length|initial|inherit;

屬性值:

  • auto:用於將height屬性設置為其默認值。如果height屬性設置為auto,則瀏覽器將計算元素的高度。

    用法:



    height:auto;

    例:

    <!DOCTYPE html> 
    <html> 
        <head> 
            <title> 
                CSS height Property 
            </title> 
              
            <style> 
                .Geeks { 
                    height:auto; 
                    color:white; 
                    font-size:30px; 
                    background-color:green; 
                } 
            </style> 
        </head> 
          
        <body> 
            <h2>CSS height Property</h2> 
              
            <div class = "Geeks"> 
                GeeksforGeeks:A computer science portal 
            </div> 
        </body> 
    </html>                    

    輸出:
    CSS_height property numeric value

  • length:用於以px,cm等形式設置元素的高度。長度不能為負數。

    用法:

    height:length;

    例:

    <!DOCTYPE html> 
    <html> 
        <head> 
            <title> 
                CSS height Property 
            </title> 
              
            <style> 
                .Geeks { 
                    height:100px; 
                    color:white; 
                    font-size:30px; 
                    background-color:green; 
                } 
            </style> 
        </head> 
          
        <body> 
            <h2>CSS height Property</h2> 
              
            <div class = "Geeks"> 
                GeeksforGeeks:A computer science portal 
            </div> 
        </body> 
    </html>                    

    輸出:
    CSS height property

  • initial:用於將height屬性設置為其默認值。

    用法:

    height:initial;

    例:

    <!DOCTYPE html> 
    <html> 
        <head> 
            <title> 
                CSS height Property 
            </title> 
              
            <style> 
                .Geeks { 
                    height:initial; 
                    color:white; 
                    font-size:30px; 
                    background-color:green; 
                } 
            </style> 
        </head> 
          
        <body> 
            <h2>CSS height Property</h2> 
              
            <div class = "Geeks"> 
                GeeksforGeeks:A computer science portal 
            </div> 
        </body> 
    </html>                    

    輸出:
    CSS height property auto

  • inherit:它用於從其父元素設置height屬性。

支持的瀏覽器:height屬性支持的瀏覽器如下:

  • 穀歌瀏覽器1.0
  • Internet Explorer 4.0
  • Firefox 1.0
  • Safari 1.0
  • Opera 7.0



相關用法


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