grid - 网格轨道对齐方式

网格轨道对齐可以相对于网格容器行和列轴。

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;

  网格剩余行空间平均分配给行之间,其中相邻两行的间距与第一行距容器行顶端间距和最后一行距容器末端的间距相等.

 

 看到这里再推荐实例演示,来自CSDN:https://blog.csdn.net/qq_41701956/article/details/80176008 ,本章节所有内容均来自https://learncssgrid.com/,由https://www.w3cplus.com译.

转载于:https://www.cnblogs.com/cisum/p/10676453.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值