网格轨道对齐可以相对于网格容器行和列轴.
align-content 指定网格轨道沿着行轴对齐方式; justify-content 指定网格轨道沿着列轴对齐方式. 它们支持下面属性:
- normal
- start
- end
- center
- stretch
- space-around
- space-between
- space-evenly
- baseline
- first baseline
- last baseline
- 1. justify-content;
- <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;
start 指定列沿着行轴开始排列, 它是 justify-content 默认值.
justify-content: end;
列沿着行末端开始排列.
justify-content: center;
列沿着行中间排列.
justify-content: space-around;
网格容器剩余列空间分配给每列的两端 (相邻两列之间的间距是第一列与容器最左侧边缘或最后一列与容器最右侧边缘间距的两倍).
justify-content: space-between;
网格容器剩余列空间平均分配给相邻的两列 (第一列与容器最左侧边缘和最后一列与容器最右侧边缘没有任何间距).
justify-content: space-evenly;
网格容器剩余列空间平均分配给列之间, 相邻两列之间的间距与第一列和容器最左侧边级和最后一列与容器最右侧边缘间距相同.
- 2.align-content
- 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;
start 允许网格网从网格容器列轴的开始位置排列, 其是 align-content 的默认值.
align-content: end;
网格行在网格容器列轴末端.
align-content:center;
网格行在网格列中间.
align-content:space-around;
网格剩余行空间分配给每行之间上下, 其中相邻两行的间距是第一行距离网格容器行顶端或者最后一行距离网格容器行末端之间间距的两倍.
align-content:space-between;
网格剩余行空间平均分配给相邻两行之间, 其中第一行紧靠网格容器行的顶端, 最后一行紧靠网格容器行的末端著作权归作者所有
align-content:space-evenly;
网格剩余行空间平均分配给行之间, 其中相邻两行的间距与第一行距容器行顶端间距和最后一行距容器末端的间距相等.
来源: http://www.bubuko.com/infodetail-3016908.html