CSS |网格-自动列属性

原文:https://www . geesforgeks . org/CSS-grid-auto-columns-property/

CSS 中的网格自动列属性用于指定隐式生成的网格容器的列大小。

语法:

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

属性值:

  • auto: It is the default value. The size is determined implicitly according to the size of the container.

    例 1:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns:  auto;

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

  • length: It is used to specify the size as integer length. Negative values are not allowed.

    示例:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns: 8.5cm;

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

  • percentage: It specifies the size as percentage value.

    示例:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column container Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns:  30%;

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

  • 最大含量:它根据容器中最大的物品来指定尺寸。

  • 最小含量:根据容器中最小的物品指定尺寸。
  • minmax(min, max): It specifies the size in the range of [min, max]. greater than or equal to min and less than or equal to max.

    示例:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns:  minmax(100px, 4cm);

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

  • initial: It sets the grid-auto-columns property to its default value.

    示例:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns: initial;

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

  • inherit: It sets the grid-auto-columns property from its parent element.

    示例:

    ```html <!DOCTYPE html>        

                            CSS grid-auto-column Property           

                  .main {                  display: grid;                  grid-template-areas: "a a";                  grid-gap: 20px;                  padding: 30px;                  background-color: green;                 grid-auto-columns:  inherit;

    }              .GFG {                  text-align: center;                  font-size: 35px;                  background-color: white;                  padding: 20px 0;              }                 

              
                  
    1
                  
    2
                  
    3
                  
    4
                  
    5
              
              ```

    输出:

支持的浏览器:网格自动列属性支持的浏览器如下:

  • Chrome 57.0
  • Edge 16.0
  • Firefox 52.0
  • Safari 10.0
  • Opera 44.0