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


CSS grid-auto-rows用法及代碼示例


CSS中的grid-auto-rows屬性用於為隱式生成的網格容器的行指定大小。

用法:

grid-auto-rows:auto|max-content|min-content|length|
percentage|minmax(min, max)|initial|inherit;

屬性值:


  • auto:這是默認值。該大小是根據容器的大小隱式確定的。

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
                
            <style>  
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:  auto; 
                    
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
            
        <body>  
            <div class = "main">  
                <div class = "GFG">1</div>  
                <div class = "GFG">2</div>  
                <div class = "GFG">3</div>  
                <div class = "GFG">4</div>  
                <div class = "GFG">5</div>  
            </div>  
        </body>  
    </html> 

    輸出:

  • length:它用於將grid-auto-rows屬性設置為給定長度。長度值不能為負。

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
                
            <style>  
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:3.5cm; 
                    
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
            
        <body>  
            <div class = "main">  
                <div class = "GFG">1</div>  
                <div class = "GFG">2</div>  
                <div class = "GFG">3</div>  
                <div class = "GFG">4</div>  
                <div class = "GFG">5</div>  
            </div>  
        </body>  
    </html> 

    輸出:

  • percentage:它將grid-auto-rows屬性設置為百分比值。

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
                
            <style>  
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:  30%; 
                    
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
            
        <body>  
            <div class = "main">  
                <div class = "GFG">1</div>  
                <div class = "GFG">2</div>  
                <div class = "GFG">3</div>  
                <div class = "GFG">4</div>  
                <div class = "GFG">5</div>  
            </div>  
        </body>  
    </html> 

    輸出:

  • max-content:根據容器中最大的項目指定大小。
  • min-content:根據容器中最小的項目指定大小。
  • minmax(min, max):指定大小,範圍為[min,max]。大於或等於min且小於或等於max。

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
                
            <style>  
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:  minmax(100px, 3.5cm); 
                    
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
            
        <body>  
            <div class = "main">  
                <div class = "GFG">1</div>  
                <div class = "GFG">2</div>  
                <div class = "GFG">3</div>  
                <div class = "GFG">4</div>  
                <div class = "GFG">5</div>  
            </div>  
        </body>  
    </html> 

    輸出:

  • initial:用其默認值初始化值。

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
                
            <style>  
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:initial; 
                    
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
            
        <body>  
            <div class = "main">  
                <div class = "GFG">1</div>  
                <div class = "GFG">2</div>  
                <div class = "GFG">3</div>  
                <div class = "GFG">4</div>  
                <div class = "GFG">5</div>  
            </div>  
        </body>  
    </html> 

    輸出:

  • inherit:從其父元素繼承值。

    例:

                            <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid-auto-rows Property  
            </title>  
              
            <style>  
                .container { 
                    grid-auto-rows:80px; 
                } 
                .main {  
                    display:grid;  
                    grid-template-areas:"a a";  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green; 
                    grid-auto-rows:inherit; 
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
            </style>  
        </head>  
          
        <body>  
            <div class = "container"> 
                <div class = "main"> 
                    <div class = "GFG">1</div>  
                    <div class = "GFG">2</div>  
                    <div class = "GFG">3</div>  
                    <div class = "GFG">4</div>  
                    <div class = "GFG">5</div>  
                </div>  
            </div>  
        </body>  
    </html>                    

    輸出:

支持的瀏覽器:下麵列出了grid-auto-rows屬性支持的瀏覽器:

  • chrome 57.0
  • 邊16.0
  • Firefox 52.0
  • Safari 10.0
  • Opera 44.0


相關用法


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