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


CSS grid-column-end用法及代碼示例


grid-column-end屬性說明項目將跨越的列數,或項目將結束在其上的column-line。它支持三種不同類型的值。

用法:

grid-column-end:auto|span n|column-line;

屬性值:


  • auto:網格項將跨越一列。它是默認值。

    用法:

    grid-column-end:auto;

    例:

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

    輸出:

  • span n:用於指定將跨越的列項目數。

    用法:

    grid-column-end:span n;

    例:

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>  
                CSS grid container Property  
            </title>  
              
            <style>  
                .main {  
                    display:grid;  
                    grid-template-columns:auto auto auto;  
                    grid-gap:20px;  
                    padding:30px;  
                    background-color:green;  
                  
                }  
                .GFG {  
                    text-align:center;  
                    font-size:35px;  
                    background-color:white;  
                    padding:20px 0;  
                }  
                .Geeks1 {  
                    grid-column-end:span 3;  
                }  
            </style>  
        </head>  
          
        <body>  
            <div class = "main">  
                <div class = "Geeks1 GFG">1</div>  
                <div class = "Geeks2 GFG">2</div>  
                <div class = "Geeks3 GFG">3</div>  
                <div class = "Geeks4 GFG">4</div>  
                <div class = "Geeks5 GFG">5</div>  
            </div>  
        </body>  
    </html>                     

    輸出:

  • column-line:它用於指定項目顯示在哪一列上結束,用戶可以設置該列的結束。

    用法:

    grid-column-end:column-line;

    例:

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

    輸出:

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

  • 穀歌瀏覽器57.0
  • Internet Explorer 16.0
  • Mozilla Firefox 52.0
  • Safari 10.0
  • Opera 44.0


相關用法


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