• Grid网格布局


    本文已参与「新人创作礼」活动,一起开启掘金创作之路

    Flex 布局是轴线布局,只能指定"项目"针对轴线的位置,可以看作是一维布局。

    Grid 布局则是将容器划分成"行"和"列",产生单元格,
    然后指定"项目所在"的单元格,可以看作是二维布局。Grid 布局远比 Flex 布局强大。

    指定一个容器采用网格布局
    *注意,设为网格布局以后,容器子元素(项目)
    的float、display: inline-block、display: table-cell、vertical-align和column-等设置都将失效。

    div {
      display: grid;
    }
    div {
      display: inline-grid; 
      /* 默认情况下,容器元素都是块级元素,但也可以设成行内元素。 */
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    基本概念

    容器和项目:采用网格布局的区域,称为"容器"(container)。
    容器内部采用网格定位的子元素,称为"项目"(item)。
    行和列:容器里面的水平区域称为"行"(row),垂直区域称为"列"(column)。
    单元格:行和列的交叉区域,称为"单元格"(cell)。
    网格线:划分网格的线,称为"网格线"(grid line)。
    水平网格线划分出行,垂直网格线划分出列。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    容器属性

    容器指定了网格布局以后,接着就要划分行和列。

    #grid-template-columns (列宽)
    grid-template-columns属性定义每一列的列宽
    
    #grid-template-rows (行高)
    grid-template-rows属性定义每一行的行高。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    /* 指定一个三行三列的网格,列宽和行高都是100px */
    .container {
      display: grid;
      grid-template-columns: 100px 100px 100px;
      grid-template-rows: 100px 100px 100px;
    }
    
    /* 也可以使用百分百单位*/
    .container {
      display: grid;
      grid-template-columns: 33.33% 33.33% 33.33%;
      grid-template-rows: 33.33% 33.33% 33.33%;
    }
    
    /* 1.repeat(count, content)  重复
     * 第一个参数是重复的次数(上例是3),第二个参数是所要重复的值
     */
    grid-template-columns: repeat(2, 100px 20px 80px);
    /* 等价于 grid-template-columns: 100px 20px 80px 100px 20px 80px */
    grid-template-rows: repeat(3, 33.33%);
    /* 等价于 grid-template-rows: 33.33% 33.33% 33.33%; */
    
    /**
     * 2.auto-fill 关键字  自动填充
     * 单元格的大小是固定的,但是容器的大小不确定。
     * 如果希望每一行(或列)容纳尽可能多的单元格,可以使用auto-fill关键字表示自动填充。
     */
     .container {
      display: grid;
      grid-template-columns: repeat(auto-fill, 100px);
      /* 每列宽度100px,然后自动填充,直到容器不能放置更多的列。 */
    }
    
    /**
     * 3.fr 关键字,(fraction 的缩写,意为"片段") 表示比例
     * 1fr和2fr,就表示后者是前者的两倍。
     */
    .container {
      display: grid;
      grid-template-columns: 1fr 1fr; /* 两列相同宽度 */
      grid-template-columns: 150px 1fr 2fr;
      /* 第一列的宽度为150像素,第二列的宽度是第三列的一半。 */
    }
    
    /**
     * 4.minmax() 范围
     * minmax(min, max)函数产生一个长度范围,表示长度就在这个范围之中。
     */
    .container {
      display: grid;
      grid-template-columns: 1fr 1fr minmax(100px, 1fr);
      /* minmax(100px, 1fr)表示列宽不小于100px,不大于1fr。 */
    }
    
     /**
      * 5.auto关键字
      * 表示由浏览器自己决定长度。
      */
    .container {
      display: grid;
      grid-template-columns: 100px auto 100px;
    }
    
    /**
     * 6.网格线名称
     * 可以使用方括号,指定每一根网格线的名字,方便以后的引用。
     */
    .container {
      display: grid;
      grid-template-columns: [c1] 100px [c2] 100px [c3] auto [c4];
      grid-template-rows: [r1] 100px [r2] 100px [r3] auto [r4];
      /* 指定网格布局为3行3列,有4根垂直网格线和4根水平网格线。方括号里面依次是这八根线的名字。 */
    }
    
    /* 例子1:
     * grid-template-columns属性对于网页布局非常有用。两栏式布局只需要一行代码。
     */
    .wrapper {
      display: grid;
      grid-template-columns: 70% 30%;
    }
    
    /* 例子2:
     * 传统的十二网格布局,写起来也很容易。
     */
     .wrapper {
      display: grid;
      grid-template-columns: repeat(12, 1fr);
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89

    grid-row-gap (行间距)

    grid-row-gap属性设置行与行的间隔(行间距)
    
    • 1

    grid-column-gap (列间距)

    grid-column-gap属性设置列与列的间隔(列间距)。
    
    • 1

    #grid-gap (行间距加列间距)

    .container {
      display: grid;
      grid-row-gap: 20px; /* 等价于 row-gap: 20px */
      grid-column-gap: 20px; /* 等价于 column-gap: 20px */
    }
    
    /* grid-gap:  ; */
    .container {
      display: grid;
      grid-gap: 20px 20px; /*等价于 gap: 20px 20px */
    }
    
    /* 如果grid-gap省略了第二个值,浏览器认为第二个值等于第一个值。 */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    grid-template-areas (标记单元格)

    .container {
      display: grid;
      grid-template-columns: 100px 100px 100px;
      grid-template-rows: 100px 100px 100px;
      /* 划分出9个单元格,将其命名为a到i的九个区域,分别对应这九个单元格。 */
      grid-template-areas: 'a b c'
                           'd e f'
                           'g h i';
    
      /* 多个单元格合并成一个区域的写法 */
      grid-template-areas: 'a a a'
                           'b b b'
                           'c c c';
    
      /* 布局实例 */
      grid-template-areas: "header header header"
                           "main main sidebar"
                           "footer footer footer";
    
      /* 如果某些元素不需要利用,以.来代替 */
      grid-template-areas: 'a . c'
                           'd . f'
                           'g . i';
    
      /* 区域的命名会影响到网格线。
      每个区域的起始网格线,会自动命名为区域名-start,
      终止网格线自动命名为区域名-end */
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    士例
    <!DOCTYPE html>
    
      
        "utf-8">
        grid<<span class="token operator">/</span>title>
        <style>
          <span class="token punctuation">.</span>container <span class="token punctuation">{<!-- --></span>
            min-height: 100vh<span class="token punctuation">;</span>
            display: grid<span class="token punctuation">;</span>
            grid-template-rows: 100px auto 100px<span class="token punctuation">;</span>
            grid-template-columns: repeat<span class="token punctuation">(</span>3<span class="token punctuation">,</span> 1fr<span class="token punctuation">)</span><span class="token punctuation">;</span>
            grid-template-areas: <span class="token string">"header header header"</span>
                                 <span class="token string">"main main sidebar"</span>
                                 <span class="token string">"footer footer footer"</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
          <span class="token punctuation">.</span>header <span class="token punctuation">{<!-- --></span>
            grid-area: header<span class="token punctuation">;</span>
            background: gray<span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
          <span class="token punctuation">.</span>main <span class="token punctuation">{<!-- --></span>
            grid-area: main<span class="token punctuation">;</span>
            background: green<span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
          <span class="token punctuation">.</span>sidebar <span class="token punctuation">{<!-- --></span>
            grid-area: sidebar<span class="token punctuation">;</span>
            background: blue<span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
          <span class="token punctuation">.</span>footer <span class="token punctuation">{<!-- --></span>
            grid-area: footer<span class="token punctuation">;</span>
            background: yellow<span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
        <<span class="token operator">/</span>style>
      <<span class="token operator">/</span>head>
      <body style=<span class="token string">"padding:0;margin:0"</span>>
        <div <span class="token keyword">class</span>=<span class="token string">"container"</span>>
            <div <span class="token keyword">class</span>=<span class="token string">"header"</span>>header<<span class="token operator">/</span>div>
            <div <span class="token keyword">class</span>=<span class="token string">"main"</span>>main<<span class="token operator">/</span>div>
            <div <span class="token keyword">class</span>=<span class="token string">"sidebar"</span>>sidebar<<span class="token operator">/</span>div>
            <div <span class="token keyword">class</span>=<span class="token string">"footer"</span>>footer<<span class="token operator">/</span>div>
        <<span class="token operator">/</span>div>
      <<span class="token operator">/</span>body>
    <<span class="token operator">/</span>html>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li></ul></pre> 
    <h4><a name="t6"></a><a id="gridautoflow_235"></a>grid-auto-flow(平铺网格顺序)</h4> 
    <p>划分网格以后,容器的子元素会按照顺序,自动放置在每一个网格。</p> 
    <pre data-index="9" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">grid-auto-flow: column<span class="token punctuation">;</span>  <span class="token operator">/</span><span class="token operator">*</span> 默认为row <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token operator">/</span><span class="token operator">*</span>
      grid-auto-flow: row  <span class="token string">"先行后列"</span>
      1 2 3
      4 5 6
      7 6 9
      grid-auto-flow: column  <span class="token string">"先列后行"</span>
      1 4 7
      2 5 8
      3 6 9
    <span class="token operator">*</span><span class="token operator">/</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre> 
    <p><img src="https://1000bd.com/contentImg/2023/10/31/000048253.png" alt="在这里插入图片描述"></p> 
    <h4><a name="t7"></a><a id="item_253"></a>单元格对齐方式item</h4> 
    <pre data-index="10" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">justify-items(单元格水平对齐)
    justify-items属性设置单元格内容的水平位置(左中右)。
    
    #align-items(单元格垂直对齐)
    align-items属性设置单元格内容的垂直位置(上中下)。
    
    start:对齐单元格的起始边缘。
    end:对齐单元格的结束边缘。
    center:单元格内部居中。
    stretch:拉伸,占满单元格的整个宽度(默认值)。
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre> 
    <pre data-index="11" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>container <span class="token punctuation">{<!-- --></span>
      justify-items: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch<span class="token punctuation">;</span>
      align-items: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
    <pre data-index="12" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">place-items(单元格水平/垂直对齐)
    place-items属性是align-items属性和justify-items属性的合并简写形式。
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
    <pre data-index="13" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">place-items: <align-items> <justify-items>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
    <h4><a name="t8"></a><a id="_content_277"></a>整体对齐 content</h4> 
    <pre data-index="14" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">ustify-content(整体内容水平对齐)
    justify-content属性是整个内容区域在容器里面的水平位置(左中右)。
    
    align-content(整体内容垂直对齐)
    align-content属性是整个内容区域的垂直位置(上中下)。
    
    place-content(整体内容水平/垂直对齐)
    	start - 对齐容器的起始边框。
    	end - 对齐容器的结束边框。
    	center - 容器内部居中。
    	stretch - 项目大小没有指定时,拉伸占据整个网格容器。
    	space-around - 每个项目两侧的间隔相等。所以,项目之间的间隔比项目与容器边框的间隔大一倍。
    	space-between - 项目与项目的间隔相等,项目与容器边框之间没有间隔。
    	space-evenly - 项目与项目的间隔相等,项目与容器边框之间也是同样长度的间隔。
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li></ul></pre> 
    <pre data-index="15" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>container <span class="token punctuation">{<!-- --></span>
      justify-content: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch <span class="token punctuation">|</span> space-around <span class="token punctuation">|</span> space-between <span class="token punctuation">|</span> space-evenly<span class="token punctuation">;</span>
      align-content: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch <span class="token punctuation">|</span> space-around <span class="token punctuation">|</span> space-between <span class="token punctuation">|</span> space-evenly<span class="token punctuation">;</span>  
      place-content: <align-content> <justify-content>
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <p><img src="https://1000bd.com/contentImg/2023/10/31/000048313.png" alt="在这里插入图片描述"></p> 
    <h2><a name="t9"></a><a id="_306"></a>项目属性</h2> 
    <p>容器和项目的概念一定要搞清楚,<br> 项目就是容器里面的盒子<br> 下图123…9就是9个项目<br> 包裹他们的是他们的容器</p> 
    <pre data-index="16" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">grid-column-start(左边框所在的垂直网格线)
    grid-column-end(右边框所在的垂直网格线)
    grid-row-start(上边框所在的水平网格线)
    grid-row-end(上边框所在的水平网格线)
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
    <p><img src="https://1000bd.com/contentImg/2023/10/31/000048243.png" alt="在这里插入图片描述"></p> 
    <pre data-index="17" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      grid-column: 1 <span class="token operator">/</span> 3<span class="token punctuation">;</span>
      grid-row: 1 <span class="token operator">/</span> 2<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token operator">/</span><span class="token operator">*</span> 等同于 <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      grid-column-<span class="token function">start</span>: 1<span class="token punctuation">;</span>
      grid-column-<span class="token keyword">end</span>: 3<span class="token punctuation">;</span>
      grid-row-<span class="token function">start</span>: 1<span class="token punctuation">;</span>
      grid-row-<span class="token keyword">end</span>: 2<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre> 
    <pre data-index="18" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      background: <span class="token comment">#b03532;</span>
      grid-column: 1 <span class="token operator">/</span> 3<span class="token punctuation">;</span>
      grid-row: 1 <span class="token operator">/</span> 3<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token operator">/</span><span class="token operator">*</span> 等同于 <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      background: <span class="token comment">#b03532;</span>
      grid-column: 1 <span class="token operator">/</span> span 2<span class="token punctuation">;</span>
      grid-row: 1 <span class="token operator">/</span> span 2<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre> 
    <h6><a id="gridarea_346"></a>grid-area(指定项目区域)</h6> 
    <pre data-index="19" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token operator">/</span><span class="token operator">*</span> 1号项目位于e区 <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      grid-area: e<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token punctuation">.</span>item <span class="token punctuation">{<!-- --></span>
      grid-area: <row-<span class="token function">start</span>> <span class="token operator">/</span> <column-<span class="token function">start</span>> <span class="token operator">/</span> <row-<span class="token keyword">end</span>> <span class="token operator">/</span> <column-<span class="token keyword">end</span>><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>item-1 <span class="token punctuation">{<!-- --></span>
      grid-area: 1 <span class="token operator">/</span> 1 <span class="token operator">/</span> 3 <span class="token operator">/</span> 3<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre> 
    <pre data-index="20" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">justify-self(单个项目水平对齐)
    
    align-self(单个项目垂直对齐)
    
    place-self(单个项目水平/垂直对齐)
    
    justify-self属性设置单元格内容的水平位置(左中右),
    跟justify-items属性的用法完全一致,但只作用于单个项目。
    
    align-self属性设置单元格内容的垂直位置(上中下),
    跟align-items属性的用法完全一致,也是只作用于单个项目。
    
    place-self属性是align-self属性和justify-self属性的合并简写形式。
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li></ul></pre> 
    <pre data-index="21" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>item <span class="token punctuation">{<!-- --></span>
      justify-self: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch<span class="token punctuation">;</span>
      align-self: <span class="token function">start</span> <span class="token punctuation">|</span> <span class="token keyword">end</span> <span class="token punctuation">|</span> center <span class="token punctuation">|</span> stretch<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token operator">/</span><span class="token operator">*</span> place-self: <align-self> <justify-self><span class="token punctuation">;</span> <span class="token operator">*</span><span class="token operator">/</span>
    place-self: center center<span class="token punctuation">;</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
    <h5><a id="_383"></a>属性简写</h5> 
    <pre data-index="22" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">grid-template<span class="token punctuation">(</span>3个属性合并写法<span class="token punctuation">)</span>
    grid-template属性是
    grid-template-columns、
    grid-template-rows
    grid-template-areas
    这三个属性的合并简写形式。
    
    grid<span class="token punctuation">(</span>6个属性合并写法<span class="token punctuation">)</span>
    grid属性是grid-template-rows、
    grid-template-columns、
    grid-template-areas、
     grid-auto-rows、
     grid-auto-columns、
     grid-auto-flow
    这六个属性的合并简写形式。
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li></ul></pre> 
    <h5><a id="_403"></a>多余的内容</h5> 
    <pre data-index="23" class="set-code-show prettyprint"><code class="has-numbering" onclick="mdcp.signin(event)" style="position: unset;">grid-auto-columns(多余网格列宽)
    grid-auto-rows(多余网格行高)
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
    <pre data-index="24" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token punctuation">.</span>container <span class="token punctuation">{<!-- --></span>
      display: grid<span class="token punctuation">;</span>
      grid-template-columns: 100px 100px 100px<span class="token punctuation">;</span>
      grid-template-rows: 100px 100px 100px<span class="token punctuation">;</span>
      grid-auto-rows: 50px<span class="token punctuation">;</span> 
    <span class="token punctuation">}</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
    <p>这个网站可以可视化的,生成你想要的布局,<br> 即使你不会grid布局,<br> <a href="https://cssgrid-generator.netlify.app/">grid生成网站,巨好用</a></p>
                    </div>
                        </div>
                    </li>
    
                    <li class="list-group-item ul-li">
    
                        <b>相关阅读:</b><br>
                        <nobr>
    <a href="/Article/Index/1323411">2023年6月电子学会Python等级考试试卷(六级)答案解析</a>                            <br />
    <a href="/Article/Index/613816">Abp 业务异常源码解读</a>                            <br />
    <a href="/Article/Index/1562499">解决SQL错误(208):对象名‘string_split‘无效的正确方法,亲测有效!!!</a>                            <br />
    <a href="/Article/Index/1680536">开源一款功能强大的 .NET 消息队列通讯模型框架 Maomi.MQ</a>                            <br />
    <a href="/Article/Index/1099802">java计算机毕业设计华夏球迷俱乐部网站设计与实现源码+mysql数据库+系统+lw文档+部署</a>                            <br />
    <a href="/Article/Index/1182900">自定义表单、自定义流程、自定义页面、自定义报表应用开发平台</a>                            <br />
    <a href="/Article/Index/1076619">老风控的心声:风控的“痛”与“恨”|内卷当下,单做好风控已远远不够</a>                            <br />
    <a href="/Article/Index/903935">Docker 操作镜像</a>                            <br />
    <a href="/Article/Index/750428">PyQt5快速开发与实战 9.5 PyQtGraph在PyQt中的应用 && 9.6 Plotly在PyQt中的应用</a>                            <br />
    <a href="/Article/Index/1107508">使用EasyCV Mask2Former轻松实现图像分割</a>                            <br />
                        </nobr>
                    </li>
                    <li class="list-group-item from-a mb-2">
                        原文地址:https://blog.csdn.net/qq_36262295/article/details/126663031
                    </li>
    
                </ul>
            </div>
    
            <div class="col-lg-4 col-sm-12">
                <ul class="list-group" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        最新文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/1484446">攻防演习之三天拿下官网站群</a>                            <br />
    <a href="/Article/Index/1515268">数据安全治理学习——前期安全规划和安全管理体系建设</a>                            <br />
    <a href="/Article/Index/1759065">企业安全 | 企业内一次钓鱼演练准备过程</a>                            <br />
    <a href="/Article/Index/1485036">内网渗透测试 | Kerberos协议及其部分攻击手法</a>                            <br />
    <a href="/Article/Index/1877332">0day的产生 | 不懂代码的"代码审计"</a>                            <br />
    <a href="/Article/Index/1887576">安装scrcpy-client模块av模块异常,环境问题解决方案</a>                            <br />
    <a href="/Article/Index/1887578">leetcode hot100【LeetCode 279. 完全平方数】java实现</a>                            <br />
    <a href="/Article/Index/1887512">OpenWrt下安装Mosquitto</a>                            <br />
    <a href="/Article/Index/1887520">AnatoMask论文汇总</a>                            <br />
    <a href="/Article/Index/1887496">【AI日记】24.11.01 LangChain、openai api和github copilot</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
                <ul class="list-group pt-2" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        热门文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/888177">十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!</a>                            <br />
    <a href="/Article/Index/797680">奉劝各位学弟学妹们,该打造你的技术影响力了!</a>                            <br />
    <a href="/Article/Index/888183">五年了,我在 CSDN 的两个一百万。</a>                            <br />
    <a href="/Article/Index/888179">Java俄罗斯方块,老程序员花了一个周末,连接中学年代!</a>                            <br />
    <a href="/Article/Index/797730">面试官都震惊,你这网络基础可以啊!</a>                            <br />
    <a href="/Article/Index/797725">你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法</a>                            <br />
    <a href="/Article/Index/797702">心情不好的时候,用 Python 画棵樱花树送给自己吧</a>                            <br />
    <a href="/Article/Index/797709">通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!</a>                            <br />
    <a href="/Article/Index/797716">13 万字 C 语言从入门到精通保姆级教程2021 年版</a>                            <br />
    <a href="/Article/Index/888192">10行代码集2000张美女图,Python爬虫120例,再上征途</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
            </div>
        </div>
    </div>
    <!-- 主体 -->
    
    
        <!--body结束-->
        <!--这里是footer模板-->
        
        <!--footer-->
    <nav class="navbar navbar-inverse navbar-fixed-bottom">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="text-muted center foot-height">
                        Copyright © 2022 侵权请联系<a href="mailto:2656653265@qq.com">2656653265@qq.com</a>   
                        <a href="https://beian.miit.gov.cn/" target="_blank">京ICP备2022015340号-1</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:0px 5px;">
                        <a href="/regex.html">正则表达式工具</a>
                        <a href="/cron.html">cron表达式工具</a>
                        <a href="/pwdcreator.html">密码生成工具</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:5px 0;">
                        <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502049817" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
                        <img src="" style="float:left;" /><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">京公网安备 11010502049817号</p></a>
                    </div>
                </div>
            </div>
        </div>
      
    </nav>
    <!--footer-->
    
        <!--footer模板结束-->
    
        <script src="/js/plugins/jquery/jquery.js"></script>
        <script src="/js/bootstrap.min.js"></script>
    
        <!--这里是scripts模板-->
        
    
        
     
    
    
        <!--scripts模板结束-->
    
    </body>
    </html>