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


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


grid-column-start屬性定義將從哪個列行項目開始。 grid-column-start屬性有不同的值,用戶可以從任何地方開始使用不同的值。在相同的命名塊上也有一個特定的值。

用法:

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

屬性值:


  • auto:一個關鍵字,指定該屬性對網格項目的位置沒有任何貢獻。默認值,該項目將在流程之後放置

    用法:

    grid-column-start:auto; 

    例:

    <!DOCTYPE html> 
    <html> 
      
    <head> 
        <title> 
            CSS | grid-column-start Property 
        </title> 
        <style> 
            .grid-container { 
                display:grid; 
                grid-template-columns:auto auto auto auto; 
                grid-gap:10px; 
                background-color:lightgreen; 
                padding:10px; 
            } 
              
            .grid-container div { 
                background-color:green; 
                text-align:center; 
                padding:20px 0; 
                font-size:30px; 
                color:white; 
            } 
              
            .item1 { 
                <!-- grid-column-start property 
                                   with auto value --> 
                grid-column-start:auto; 
            } 
        </style> 
    </head> 
      
    <body> 
      
        <center> 
            <h1> 
             The grid-column-start Property 
            </h1> 
            <h3>auto value</h3> 
            <strong>the item will be placed 
                   following the initial flow</strong> 
       </center> 
      
        <div class="grid-container"> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
            <div class="item5">f</div> 
            <div class="item6">o</div> 
            <div class="item6">r</div> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
        </div> 
      
    </body> 
      
    </html>

    輸出:

  • span n:關鍵字指定項目將跨越的列數,如果名稱以a給出,則僅計算具有該名稱的行

    用法:

    grid-column-start:span n; 

    例:

    <!DOCTYPE html> 
    <html> 
      
    <head> 
        <title> 
            CSS | grid-column-start Property 
        </title> 
        <style> 
            .grid-container { 
                display:grid; 
                grid-template-columns:auto auto auto auto; 
                grid-gap:10px; 
                background-color:lightgreen; 
                padding:10px; 
            } 
              
            .grid-container div { 
                background-color:green; 
                text-align:center; 
                padding:20px 0; 
                font-size:30px; 
                color:white; 
            } 
              
            .item1 { 
                <!-- grid-column-start property  
                                    with span value --> 
                grid-column-start:span 4; 
            } 
        </style> 
    </head> 
      
    <body> 
      
         <center> 
            <h1> 
             The grid-column-start Property 
            </h1> 
            <h3>auto value</h3> 
            <strong>the item will be placed following  
                               the initial flow</strong> 
        </center> 
        <div class="grid-container"> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
            <div class="item5">f</div> 
            <div class="item6">o</div> 
            <div class="item6">r</div> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
        </div> 
      
    </body> 
      
    </html>

    輸出:


  • column-line:關鍵字指定在哪個列上開始顯示項目,用戶可以設置起始列。

    用法:

    grid-column-start:column-line; 

    例:

    <!DOCTYPE html> 
    <html> 
      
    <head> 
        <title> 
            CSS | grid-column-start Property 
        </title> 
        <style> 
            .grid-container { 
                display:grid; 
                grid-template-columns:auto auto auto auto; 
                grid-gap:10px; 
                background-color:lightgreen; 
                padding:10px; 
            } 
              
            .grid-container div { 
                background-color:green; 
                text-align:center; 
                padding:20px 0; 
                font-size:30px; 
                color:white; 
            } 
              
            .item1 { 
                <!-- grid-column-start property  
                                with column-line value --!>  
              grid-column-start:2; 
            } 
                
        </style> 
    </head> 
      
    <body> 
      
        <center> 
            <h1> 
             The grid-column-start Property 
            </h1> 
            <h3>auto value</h3> 
            <strong>the item will be placed following  
                                the initial flow</strong> 
        </center> 
        <div class="grid-container"> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
            <div class="item5">f</div> 
            <div class="item6">o</div> 
            <div class="item6">r</div> 
            <div class="item1">G</div> 
            <div class="item2">e</div> 
            <div class="item2">e</div> 
            <div class="item3">k</div> 
            <div class="item4">s</div> 
        </div> 
      
    </body> 
      
    </html>

    輸出:

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

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


相關用法


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