CSS的Box Alignment Module补充了网格项目沿着网格行或列轴对齐方式。

 <view class="grid">
<view class='item1'>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 class='item'>9</view> -->
</view>
 page {
color: #fff;
font-size: 16px;
} .grid {
/* padding: 1%; */
display: grid;
grid-template-rows: 80px 80px;
grid-template-columns: 1fr 1fr;
grid-template-areas: "content content" "content content";
border: 1px solid #ccc;
} .grid {
justify-items: start;
/* justify-items: end; */
/* justify-items: center; */
/* justify-items: stretch; */
} .item1 {
grid-area: content;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #fff;
border-radius: 0.2rem;
font-size: 0.8em;
min-height: 3rem;
padding: 0.75rem;
color: #f0f0f3;
/* background-color: #e91e63; */
} .item {
text-align: center;
background-color: #d94a6a;
} .item1 {
/* text-align: center; */
background-color: #1aa034;
}

justify-itemsjustify-self指定网格项目沿着行轴对齐方式;align-itemsalign-self指定网格项目沿着列轴对齐方式。

justify-itemsalign-items应用在网格容器上,它们的属性值有:

  • auto
  • normal
  • start
  • end
  • center
  • stretch
  • baseline
  • first baseline
  • last baseline

1. justify-items

  • stretch

2. align-items

align-items: stretch(网格项目横跨整个列)

网格项目定位在网格行和列的中间(实现水平垂直居中)。

  

 <view class="grid">
<view class='item1'>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 class='item'>9</view> -->
</view>
 page {
color: #fff;
font-size: 16px;
} .grid {
/* padding: 1%; */
display: grid;
grid-template-rows: 80px 80px;
grid-template-columns: 1fr 1fr;
grid-template-areas: "content content" "content content";
border: 1px solid #ccc;
} .grid {
justify-items: center;
align-items: center;
/* align-items: start; */
/* align-items: center; */
/* align-items: end; */
/* justify-items: start; */
/* justify-items: end; */
/* justify-items: center; */
/* justify-items: stretch; */
} .item1 {
grid-area: content;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #fff;
border-radius: 0.2rem;
font-size: 0.8em;
min-height: 3rem;
padding: 0.75rem;
color: #f0f0f3;
/* background-color: #e91e63; */
} .item {
text-align: center;
background-color: #d94a6a;
} .item1 {
/* text-align: center; */
background-color: #1aa034;
}
  justify-items: center;
align-items: center;

  

 

grid - 网格项目对齐方式(Box Alignment)的更多相关文章

  1. grid - 网格轨道对齐方式

    网格轨道对齐可以相对于网格容器行和列轴. align-content指定网格轨道沿着行轴对齐方式:justify-content指定网格轨道沿着列轴对齐方式.它们支持下面属性: normal star ...

  2. grid - 网格项目层级

    网格项目可以具有层级和堆栈,必要时可能通过z-index属性来指定. 1.在这个例子中,item1和item2的开始行都是1,item1列的开始是1,item2列的开始是2,并且它们都跨越两列.两个网 ...

  3. grid - 网格项目跨行或跨列

    默认情况下网格项目跨度只有一个列和行,但可以跨越多个行和列. 1.可以通过设置grid-column-end和grid-column-start距离多个网络线号实现多个列跨越. <view cl ...

  4. Grid 网格布局

    CSS 网格布局(Grid Layout) 是CSS中最强大的布局系统. 这是一个二维系统,这意味着它可以同时处理列和行,不像 flexbox 那样主要是一维系统. 你可以通过将CSS规则应用于父元素 ...

  5. grid - 通过网格区域命名和定位网格项目

    1.像网格线名称一样,网格区域的名称也可以使用grid-template-areas属性来命名.引用网格区域名称也可以设置网格项目位置. 设置网格区域的名称应该放置在单引号或双引号内,每个名称由一个空 ...

  6. grid - 使用相同的名称命名网格线和设置网格项目位置

    1.使用repeat()函数可以给网格线分配相同的名称.这可以节省一定的时间 使用repeat()函数可以给网格线命名,这也导致多个网格线具有相同的网格线名称. 相同网格线名称指定网格线的位置和名称, ...

  7. grid - 通过网格线名称设置网格项目位置

    使用网格线名称设置网格项目位置和使用网格线号码设置网格项目位置类似. 1.引用网格线名称的时候不应该带方括号 <view class="grid"> <view ...

  8. grid - 通过网格线号码来定位网格项目

    网格线实际上是代表线的开始.结束. 两者之间就是网格列或行. 以下css仅对子元素生效 ,具体详情可以看后面示例 grid-row-start: 2; grid-row-end: 3; grid-co ...

  9. grid网格布局使用

    定义 grid布局是指对网页进行划分成一个一个网格,然后根据自己的要求,可以任意组合. 以前写类似的功能,很麻烦,需要写很多的CSS去控制,有了grid就很方便了,可以随意进行组合. 跟flex有很多 ...

随机推荐

  1. SSM整合——完全版

    1, 2, 3, 4,项目建立好后: 覆盖pom.xml,地址在:https://blog.csdn.net/mark_lirenhe/article/details/80875266 alt+F5= ...

  2. P1057 传球游戏 dp

    题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:nn个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个 ...

  3. LBS基站定位

    LBS基站定位(Location Based Service,简称LBS)一般应用于手机用户,它是基于位置的服务,通过电信.移动运营商的无线电通讯网络(如GSM网.CDMA网)或外部定位方式(如GPS ...

  4. Nginx的配置安装和使用

    http://blog.csdn.net/e421083458/article/details/30086413 以后继续更新

  5. (openssl_pkey_get_private 函数不存在)phpstudy开启openssl.dll 时提示httpd.exe 丢失libssl-1_1.dll

    下载libssl-1_1.dll  丢到apache目录下的bin目录下(貌似要32位的)

  6. group by 和where 条件后面不能用刚设置的别名。

    select count(*),c_xy_bj a from z_user group by c_xy_bj     这个group by后面不能使用c_xy_bj 字段的别名a,只有外面再嵌套sel ...

  7. 贪心+优先队列之更改优先级-hdu1896

    题目描述: 题目理解: Sempr从位置0往前走,一路上他会遇到石子,如果这颗石子是他遇到的第奇数颗石子,那么他就把石子往前扔出去,如果他遇到的是第偶数颗石子,他会把它留在原地.需要注意的是,Semp ...

  8. TF:TF下CNN实现mnist数据集预测 96%采用placeholder用法+2层C及其max_pool法+隐藏层dropout法+输出层softmax法+目标函数cross_entropy法+AdamOptimizer算法

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 ...

  9. 关于pycharm中安装第三方库时报错的解决办法(一)

    记录自己的生活!   一.事发背景 在pycharm中直接安装第三方库时因为版本问题总是无法安装成功,事情不大,但是很重要.   二.经过 最开始我自己电脑上安装了Python3.6和Python2. ...

  10. c++ <vector>学习

    https://www.cnblogs.com/mr-wid/archive/2013/01/22/2871105.html 具体参考上面博客,很详细,也是看他的.今天c++学习200%,项目开发0% ...