首页 > 其他 > 详细

grid - 网格轨道对齐方式

时间:2019-04-09 13:58:34      阅读:187      评论:0      收藏:0      [点我收藏+]

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

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;

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

技术分享图片

 

 

grid - 网格轨道对齐方式

原文:https://www.cnblogs.com/cisum/p/10676453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!