網格軌道對齊能夠相對於網格容器行和列軸。css
align-content
指定網格軌道沿着行軸對齊方式;justify-content
指定網格軌道沿着列軸對齊方式。它們支持下面屬性:html
normal
start
end
center
stretch
space-around
space-between
space-evenly
baseline
first baseline
last baseline
1. justify-content;spa
<view class="grid">
<view class='item'>1</view>
<view class='item'>2</view>
<view class='item'>3</view>
<view class='item'>4</view>
<view class='item'>5</view>
<view class='item'>6</view>
<view class='item'>7</view>
<view class='item'>8</view>
</view>
page { color: #fff; font-size: 16px; } .grid { /* padding: 1%; */ display: grid; width: 100%; height: 300px; grid-template-columns: repeat(4, 45px); grid-template-rows: repeat(4, 45px); grid-gap: 0.5em; border: 1px solid #eee; } .grid {
//更改這裏便可 justify-content: start; } .item { text-align: center; background-color: #1aa034; line-height: 2.5rem; }
justify-content: start;
指定列沿着行軸開始排列,它是默認值.startjustify-content
justify-content: end;
列沿着行末端開始排列。
justify-content: center;
列沿着行中間排列.
justify-content: space-around;
網格容器剩餘列空間分配給每列的兩端(相鄰兩列之間的間距是第一列與容器最左側邊緣或最後一列與容器最右側邊緣間距的兩倍)。
justify-content: space-between;
網格容器剩餘列空間平均分配給相鄰的兩列(第一列與容器最左側邊緣和最後一列與容器最右側邊緣沒有任何間距)。
justify-content: space-evenly;
網格容器剩餘列空間平均分配給列之間,相鄰兩列之間的間距與第一列和容器最左側邊級和最後一列與容器最右側邊緣間距相同.
2.align-content.net
page { color: #fff; font-size: 16px; } .grid { /* padding: 1%; */ display: grid; width: 100%; height: 300px; grid-template-columns: repeat(4, 45px); grid-template-rows: repeat(4, 45px); grid-gap: 0.5em; border: 1px solid #eee; } .grid { align-content: start; } .item { text-align: center; background-color: #1aa034; line-height: 2.5rem; }
align-content: start;3d
start
容許網格網從網格容器列軸的開始位置排列,其是align-content
的默認值.code
align-content: end;orm
網格行在網格容器列軸末端。htm
align-content:center;blog
網格行在網格列中間。rem
align-content:space-around;
網格剩餘行空間分配給每行之間上下,其中相鄰兩行的間距是第一行距離網格容器行頂端或者最後一行距離網格容器行末端之間間距的兩倍.
align-content:space-between;
網格剩餘行空間平均分配給相鄰兩行之間,其中第一行緊靠網格容器行的頂端,最後一行緊靠網格容器行的末端著做權歸做者全部
align-content:space-evenly;
網格剩餘行空間平均分配給行之間,其中相鄰兩行的間距與第一行距容器行頂端間距和最後一行距容器末端的間距相等.
看到這裏再推薦實例演示,來自CSDN:https://blog.csdn.net/qq_41701956/article/details/80176008 ,本章節全部內容均來自https://learncssgrid.com/,由https://www.w3cplus.com譯.