轉(zhuǎn)載地址:https://www.cnblogs.com/xiaohuochai/p/7083153.html
前面的話
Grid布局方式借鑒了平面裝幀設(shè)計中的格線系統(tǒng)赞辩,將格線運用在屏幕上,而不再是單一的靜態(tài)頁面糟需,可以稱之為真正的柵格圆凰。本文將詳細介紹grid布局
引入
對于Web開發(fā)者來說挑童,網(wǎng)頁布局一直是個比較重要的問題菇民。但實際上玉雾,在網(wǎng)頁開發(fā)很長的一段時間當(dāng)中,我們甚至沒有一個比較完整的布局模塊壁涎。總的來說 Web 布局經(jīng)歷了以下四個階段:
1竟坛、table表格布局洼冻,通過 Dreamweaver 拖拽表格或者手寫 table 標(biāo)簽布局
2、float浮動及position定位布局,借助元素元素盒模型本身的特性以及 float position 等屬性等進行布局
3、flex彈性盒模型布局,革命性的突破斟冕,解決傳統(tǒng)布局方案上的三大痛點 排列方向十办、對齊方式,自適應(yīng)尺寸再扭。是目前最為成熟和強大的布局方案
4、grid柵格布局赡突,二維布局模塊,具有強大的內(nèi)容尺寸和定位能力,適合需要在兩個維度上對齊內(nèi)容的布局
Grid Layout 是一種基于二維網(wǎng)格的布局系統(tǒng),旨在完全改變我們設(shè)計基于網(wǎng)格的用戶界面的方式,彌補網(wǎng)頁開發(fā)在二維布局能力上的缺陷
與flex分為伸縮容器和伸縮項目類似,grid也分為網(wǎng)格容器和網(wǎng)格項目
網(wǎng)格容器
display
通過display屬性設(shè)置屬性值為grid或inline-grid可以創(chuàng)建一個網(wǎng)格容器般眉。網(wǎng)格容器中的所有子元素就會自動變成網(wǎng)格項目(grid item)
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">display: grid
display: inline-grid</pre>
網(wǎng)格項目默認(rèn)放在行中冗酿,并且跨網(wǎng)格容器的全寬
<iframe src="https://demo.xiaohuochai.site/css/grid/g1.html" frameborder="0" width="320" height="240" style="width: 701px; height: 222px;"></iframe>
顯式網(wǎng)格
使用grid-template-columns和grid-template-rows屬性可以顯式的設(shè)置一個網(wǎng)格的列和行
【grid-template-rows】
默認(rèn)值為none
grid-template-rows指定的每個值可以創(chuàng)建每行的高度。行的高度可以是任何非負(fù)值襟沮,長度可以是px剥哑、%、em等長度單位的值
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: 60px 40px</pre>
item1和item2具有固定的高座哩,分別為60px和40px姜骡。因為只定義了兩個行的高度值尘惧,所以item3和item4的高度是根據(jù)其自身的內(nèi)容來定義啥么。
<iframe src="https://demo.xiaohuochai.site/css/grid/g2.html" frameborder="0" width="320" height="240" style="width: 701px; height: 356px;"></iframe>
【grid-template-columns】
默認(rèn)值為none
像行一樣似踱,通過grid-template-columns指定的每個值來創(chuàng)建每列的列寬
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-columns: 40px 50px 60px</pre>
item4和item5放置在新的一行(第二行),因為grid-template-columns只定義了三列的大小驰坊,它們也分別放置在列1、列2和列3;其中列1譬猫、列2和列3的尺寸大小等于item1叨恨、item2和item3寬度诚亚。item1益愈、item2和item3具有固定的寬度值敏释,分別為40px靠汁、50px和60px
<iframe src="https://demo.xiaohuochai.site/css/grid/g3.html" frameborder="0" width="320" height="240" style="width: 701px; height: 326px;"></iframe>
【fr】
fr單位可以幫助我們創(chuàng)建一個彈列的網(wǎng)格軌道奶浦。它代表了網(wǎng)格容器中可用的空間(就像Flexbox中無單位的值)
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-columns: 1fr 1fr 2fr</pre>
在這個示例中,網(wǎng)格容器分成了4等份(1 + 1 + 2 = 4),每一份(1fr)是網(wǎng)格容器寬度的四分之一瓶殃。所以item1和item2的寬度是網(wǎng)格容器的四分之一寬,item3是網(wǎng)格容器寬度的四分之二(2fr)
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-columns: 3rem 25% 1fr 2fr</pre>
當(dāng)fr
和其它長度單位的值結(jié)合在一起的時候,fr
是基于網(wǎng)格容器可用空間來計算继薛。
在這個示例中遏考,網(wǎng)格容器可用空間是網(wǎng)格寬度減去3rem
和25%
剩下的寬度,而fr
就是基于這個尺寸計算:
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">1fr = (網(wǎng)格寬度 - 3rem - 網(wǎng)格寬度 * 25%) / 3</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g4.html" frameborder="0" width="320" height="240" style="width: 701px; height: 378px;"></iframe>
【minmax()】
可以通過minmax()函數(shù)來創(chuàng)建網(wǎng)格軌道的最小或最大尺寸青团。minmax()函數(shù)接受兩個參數(shù):第一個參數(shù)定義網(wǎng)格軌道的最小值督笆,第二個參數(shù)定義網(wǎng)格軌道的最大值娃肿≈槭可以接受任何長度值,也接受auto值晒杈。auto值允許網(wǎng)格軌道基于內(nèi)容的尺寸拉伸或擠壓
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: minmax(100px, auto);
grid-template-columns: minmax(auto, 50%) 1fr 3em;</pre>
在這個示例中孔厉,第一行的高度最小值是100px,但其最大值為auto说庭,允許行的高度可以變大超過100px郑趁。第一列設(shè)置了最小值為auto,但它的最大值是50%舅柜,也就是列的最大寬度不會超過網(wǎng)格容器寬度的50%
<iframe src="https://demo.xiaohuochai.site/css/grid/g5.html" frameborder="0" width="320" height="240" style="width: 701px; height: 368px;"></iframe>
【repeat()】
使用repeat()可以創(chuàng)建重復(fù)的網(wǎng)格軌道致份。這個適用于創(chuàng)建相等尺寸的網(wǎng)格項目和多個網(wǎng)格項目础拨。repeat()接受兩個參數(shù):第一個參數(shù)定義網(wǎng)格軌道應(yīng)該重復(fù)的次數(shù),第二個參數(shù)定義每個軌道的尺寸滔蝉。
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: repeat(3, 1fr);
grid-template-columns: 30px repeat(3, 1fr) 30px;</pre>
在這個示例中塔沃,第一列和最后一列的寬度都是30px蛀柴,并且它們之間有另列三列,這三列是通過repeat()來創(chuàng)建的鸽疾,而且每列的列寬是1fr(1fr = (網(wǎng)格寬度 - 30px - 30px) / 3)
<iframe src="https://demo.xiaohuochai.site/css/grid/g6.html" frameborder="0" width="320" height="240" style="width: 701px; height: 378px;"></iframe>
間距
【grid-column-gap】
創(chuàng)建列與列之間的間距
【grid-row-gap】
創(chuàng)建行與行之間的間距
【grid-gap】
默認(rèn)值為0
grid-gap是grid-row-gap和grid-column-gap兩個屬性的縮寫,如果它指定了兩個值融蹂,那么第一個值是設(shè)置grid-row-gap的值超燃,第二個值設(shè)置grid-column-gap的值拘领。如果只設(shè)置了一個值,表示行和列的間距相等约素,也就是說grid-row-gap和grid-column-gap的值相同
[注意]grid-gap只能創(chuàng)建列與列或行與行之間的間距圣猎,但不能創(chuàng)建列和行與網(wǎng)格容器邊緣的間距
間距(Gap)可以設(shè)置任何非負(fù)值,長度值可以是px慢显、%、em等單位值
<iframe src="https://demo.xiaohuochai.site/css/grid/g7.html" frameborder="0" width="320" height="240" style="width: 701px; height: 396px;"></iframe>
網(wǎng)格項目
網(wǎng)格線
【grid-row-start】
【grid-row-end】
【grid-column-start】
【grid-column-end】
默認(rèn)值為auto
通過網(wǎng)格線可以定位網(wǎng)格項目荚藻。網(wǎng)格線實際上是代表線的開始、結(jié)束共郭,兩者之間就是網(wǎng)格列或行除嘹。每條線是從網(wǎng)格軌道開始岸蜗,網(wǎng)格的網(wǎng)格線從1開始,每條網(wǎng)格線逐步增加1
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-row-start: 2;
grid-row-end: 3;
grid-column-start: 2;
grid-column-end: 3; </pre>
兩列三行的網(wǎng)格創(chuàng)建三條列網(wǎng)格線和四條行網(wǎng)格線。item1就是由行和列的號碼重新定位蟆肆。如果一個網(wǎng)格項目跨度只有一行或一列,那么grid-row-end和grid-olumn-end不是必需的
<iframe src="https://demo.xiaohuochai.site/css/grid/g8.html" frameborder="0" width="320" height="240" style="width: 701px; height: 385px;"></iframe>
【grid-row】
【grid-column】
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-row: 2;
grid-column: 3 / 4;</pre>
grid-row是grid-row-start和grid-row-end的簡寫枚冗。grid-column是grid-column-start和grid-column-end的簡寫赁温。如果只提供一個值淤齐,則指定了grid-row-start(grid-column-start)值;如果提供兩個值稚疹,第一個值是grid-row-start(grid-column-start)的值祭务,第二個值是grid-row-end(grid-column-end)的值,兩者之間必須要用/隔開
默認(rèn)值為auto
【span】
關(guān)鍵詞span后面緊隨數(shù)字柳沙,表示合并多少個列或行
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-row: 1 / span 3;
grid-column: span 2;</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g9.html" frameborder="0" width="320" height="240" style="width: 701px; height: 331px;"></iframe>
【grid-area】
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-area: 2 / 2 / 3 / 3;</pre>
如果指定四個值赂鲤,第一個值對應(yīng)grid-row-start,第二個值對應(yīng)grid-column-start蛤袒,第三個值對應(yīng)grid-row-end,第四個值對應(yīng)grid-column-end
<iframe src="https://demo.xiaohuochai.site/css/grid/g10.html" frameborder="0" width="320" height="240" style="width: 701px; height: 397px;"></iframe>
網(wǎng)格線命名
通過grid-template-rows和grid-template-columns定義網(wǎng)格時妙真,網(wǎng)格線可以被命名。網(wǎng)格線名稱也可以設(shè)置網(wǎng)格項目位置
分配網(wǎng)格線名稱必須用方括號[網(wǎng)格線名稱]练般,然后后面緊跟網(wǎng)格軌道的尺寸值锈候。定義網(wǎng)格線名稱時需要避免使用規(guī)范中出現(xiàn)的關(guān)鍵詞,以免導(dǎo)致混亂摄职。
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: [row-1-start] 1fr [row-2-start] 1fr [row-2-end];
grid-template-columns: [col-1-start] 1fr [col-2-start] 1fr [col-3-start] 1fr [col-3-end];</pre>
可以在方括號中添加多個名稱來命名網(wǎng)格線名稱谷市,使用多外名稱命名網(wǎng)格線名稱時击孩,名稱間要用空格隔開。每一個網(wǎng)格線的名稱可以用來定位網(wǎng)格項目的位置
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: [row-start row-1-start] 1fr [row-1-end row-2-start] 1fr [row-2-end row-end];
grid-template-columns: [col-start] 1fr [col-2-start] 1fr [col-3-start] 1fr [col-end];</pre>
使用網(wǎng)格線名稱設(shè)置網(wǎng)格項目位置和使用網(wǎng)格線號碼設(shè)置網(wǎng)格項目位置類似,引用網(wǎng)格線名稱的時候不應(yīng)該帶方括號
<iframe src="https://demo.xiaohuochai.site/css/grid/g11.html" frameborder="0" width="320" height="240" style="width: 701px; height: 427px;"></iframe>
使用repeat()函數(shù)可以給網(wǎng)格線分配相同的名稱括蝠。這可以節(jié)省一定的時間忌警。
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: repeat(3, [row-start] 1fr [row-end]);
grid-template-columns: repeat(3, [col-start] 1fr [col-end]);</pre>
使用repeat()函數(shù)可以給網(wǎng)格線命名,這也導(dǎo)致多個網(wǎng)格線具有相同的網(wǎng)格線名稱慨蓝。相同網(wǎng)格線名稱指定網(wǎng)格線的位置和名稱礼烈,也且會自動在網(wǎng)格線名稱后面添加對應(yīng)的數(shù)字,使其網(wǎng)格線名稱也是唯一的標(biāo)識符
使用相同的網(wǎng)格線名稱可以設(shè)置網(wǎng)格項目的位置庭呜。網(wǎng)格線的名稱和數(shù)字之間需要用空格分開
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-row: row-start 2 / row-end 3;
grid-column: col-start / col-start 3;</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g12.html" frameborder="0" width="320" height="240" style="width: 701px; height: 390px;"></iframe>
網(wǎng)格區(qū)域命名
【grid-template-areas】
像網(wǎng)格線名稱一樣,網(wǎng)格區(qū)域的名稱可以使用grid-template-areas屬性來命名扶关。引用網(wǎng)格區(qū)域名稱也可以設(shè)置網(wǎng)格項目位置
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-areas: "header header" "content sidebar" "footer footer";
grid-template-rows: 150px 1fr 100px;
grid-template-columns: 1fr 200px;</pre>
設(shè)置網(wǎng)格區(qū)域的名稱應(yīng)該放置在單引號或雙引號內(nèi)节槐,每個名稱由一個空格符分開铜异。網(wǎng)格區(qū)域的名稱秸架,每組(單引號或雙引號內(nèi)的網(wǎng)格區(qū)域名稱)定義了網(wǎng)格的一行,每個網(wǎng)格區(qū)域名稱定義網(wǎng)格的一列
[注意]grid-template-areas: "header header" "content sidebar" "footer footer";不可以簡寫為grid-template-areas: "header" "content sidebar" "footer";
grid-row-start蚂子、grid-row-end缭黔、grid-column-start和grid-column-end以及簡寫的grid-row、grid-column董瞻、grid-area都可以引用網(wǎng)格區(qū)域名稱田巴,用來設(shè)置網(wǎng)格項目位置
<iframe src="https://demo.xiaohuochai.site/css/grid/g13.html" frameborder="0" width="320" height="240" style="width: 701px; height: 393px;"></iframe>
隱式網(wǎng)格
【grid-auto-flow】
網(wǎng)格默認(rèn)流方向是row挟秤,可以通過grid-auto-flow屬性把網(wǎng)格流的方向改變成column
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-auto-flow: column</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g14.html" frameborder="0" width="320" height="240" style="width: 701px; height: 262px;"></iframe>
當(dāng)網(wǎng)格項目確認(rèn)在顯式網(wǎng)格之外時就會創(chuàng)建隱性網(wǎng)格艘刚,當(dāng)沒有足夠的空間或者顯式的網(wǎng)格軌道來設(shè)置網(wǎng)格項目,此時網(wǎng)格項目就會自動創(chuàng)建隱式網(wǎng)格
【grid-auto-rows】
【grid-auto-columns】
使用grid-auto-rows和grid-auto-columns屬性可以定義隱式的網(wǎng)格
默認(rèn)值為auto
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: 70px;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 140px;</pre>
在上面這個例子中我們只定義了一行(軌道)箩朴,所以item1和item2的高都是70px炸庞。第二行(軌道)自動創(chuàng)建了item3和item4空間荚斯。grid-auto-rows定義隱式網(wǎng)格中的行(軌道)的大小,因此item3和item4的高度是140px
<iframe src="https://demo.xiaohuochai.site/css/grid/g15.html" frameborder="0" width="320" height="240" style="width: 701px; height: 445px;"></iframe>
隱式命名
【隱式命名網(wǎng)格區(qū)域名稱】
通持窖眨可以將網(wǎng)格線命名成任何想命名的名稱胁孙,如果網(wǎng)格線名稱添加-start和-end的后綴金踪,其實也隱式的創(chuàng)建一個網(wǎng)格區(qū)域胡岔,可以用來設(shè)置網(wǎng)格項目的位置
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-rows: [outer-start] 1fr [inner-start] 1fr [inner-end] 1fr [outer-end];
grid-template-columns: [outer-start] 1fr [inner-start] 1fr [inner-end] 1fr [inner-end];</pre>
在這個示例中法希,行和列都具有inner-start和inner-end網(wǎng)格線名稱,同時也對應(yīng)的創(chuàng)建一個隱式網(wǎng)格區(qū)域名稱inner
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-area: inner</pre>
網(wǎng)格項目定位可以通過網(wǎng)格區(qū)域名稱來設(shè)置靶瘸,而不需要使用網(wǎng)格線名稱
【隱式命名網(wǎng)格線名稱】
隱式的指定網(wǎng)格線反向指定了隱式的網(wǎng)格區(qū)域名稱苫亦,命名的網(wǎng)格區(qū)域隱式的命名了網(wǎng)格線名稱
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-template-areas: "header header" "content sidebar" "footer footer";
grid-template-rows: 80px 1fr 40px;
grid-template-columns: 1fr 200px;</pre>
指定網(wǎng)格區(qū)域會給網(wǎng)格區(qū)域邊線添加隱式的網(wǎng)格線名稱。這些網(wǎng)格線的命名是基于網(wǎng)格區(qū)域來命名怨咪,只是在網(wǎng)格區(qū)域名稱的后面添加后綴-start或-end
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">grid-row-start: header-start;
grid-row-end: content-start;
grid-column-start: footer-start;
grid-column-end: sidebar-end;</pre>
在這個示例中屋剑,header
通過隱式的網(wǎng)格線名稱設(shè)置其位置
網(wǎng)格項目層級
網(wǎng)格項目可以具有層級和堆棧,必要時可能通過z-index屬性來指定
[](javascript:void(0); "復(fù)制代碼")
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">.item-1,.item-2 { grid-row-start: 1; grid-column-end: span 2;
} .item-1 { grid-column-start: 1; z-index: 1;
} .item-2 { grid-column-start: 2 }</pre>
](javascript:void(0); "復(fù)制代碼")
在這個例子中诗眨,item1和item2的開始行都是1唉匾,item1列的開始是1,item2列的開始是2匠楚,并且它們都跨越兩列巍膘。兩個網(wǎng)格項目都是由網(wǎng)格線數(shù)字定位,結(jié)果這兩個網(wǎng)格項目重疊了芋簿。
默認(rèn)情況下峡懈,item2在item1上面肪康,但是,我們在item1中設(shè)置了z-index:1;雾狈,導(dǎo)致item1在item2之上
<iframe src="https://demo.xiaohuochai.site/css/grid/g16.html" frameborder="0" width="320" height="240" style="width: 701px; height: 410px;"></iframe>
對齊
【網(wǎng)格項目對齊方式(Box Alignment)】
CSS的Box Alignment Module補充了網(wǎng)格項目沿著網(wǎng)格行或列軸對齊方式茉帅。
【justify-items】
【justify-self】
justify-items和justify-self指定網(wǎng)格項目沿著行軸對齊方式堪澎;align-items和align-self指定網(wǎng)格項目沿著列軸對齊方式。
justify-items和align-items應(yīng)用在網(wǎng)格容器上
【align-items】
【align-self】
align-self和justify-self屬性用于網(wǎng)格項目自身對齊方式
這四個屬性主要接受以下屬性值:
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">auto | normal | start | end | center | stretch | baseline | first baseline | last baseline</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g17.html" frameborder="0" width="320" height="240" style="width: 701px; height: 423px;"></iframe>
【網(wǎng)格軌道對齊方式】
網(wǎng)格軌道對齊可以相對于網(wǎng)格容器行和列軸。
align-content指定網(wǎng)格軌道沿著行軸對齊方式便脊;justify-content指定網(wǎng)格軌道沿著列軸對齊方式。它們支持下面屬性:
<pre style="margin: 0px; white-space: pre-wrap; word-wrap: break-word; padding: 0px; list-style-type: none; list-style-image: none; font-family: "Courier New" !important; font-size: 12px !important;">normal | start | end | center | stretch | space-around | space-between | space-evenly | baseline | first baseline | last baseline</pre>
<iframe src="https://demo.xiaohuochai.site/css/grid/g18.html" frameborder="0" width="320" height="240" style="width: 701px; height: 423px;"></iframe>