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. sql 分隔字符串函数

    USE [tms]GO/****** Object: UserDefinedFunction [dbo].[fn_ConvertListToTable_Sort] Script Date: 2017/ ...

  2. 犹记当年写出bug睡不着,回想今天只求睡好渡余生……

    不想面对已经在博客园注册了3年多的时间 了,就是这么快的就已经过去了近3年的工作时间,从最开始的对编程的困惑到慢慢有一点的认识,好像哦就这样没有什么啊,也没有涉及到一些比较难的东西. 但是当初第一份工 ...

  3. P3150 pb的游戏(1)

    P3150 pb的游戏(1)选偶数,这一轮一定会活,选奇数,自己这一轮可能会死,并且(如果自己这一轮没死)下一轮对手一定可以活,因为选了奇数,就会被分解成奇数和偶数. #include<iost ...

  4. logback中logger详解

    前言 logback实践笔记 ​ 上一篇主要对root进行了实践总结,现在基于上一篇中的springboot代码环境对logback.xml中的logger来进行实践和自己遇到的坑. logger简介 ...

  5. oracle中to_timestamp和to_date什么区别

    date类型是Oracle常用的日期型变量,时间间隔是秒.两个日期型相减得到是两个时间的间隔,注意单位是“天”. timestamp是DATE类型的扩展,可以精确到小数秒(fractional_sec ...

  6. eslint那些事儿

    eslint是一个插件化的javascript和jsx代码检测工具,eslint使用Node.js编写.全局安装的eslint只能使用全局安装的插件,本地安装的eslint不仅可以使用本地安装的插件还 ...

  7. HOJ3237----BFS/DFS

    /* 注意两点 . 不可以使用替换可用节点为不可用节点的方法进行DFS 因为角落也可能有油,替换了就出不来.(某学长指导) . 可用通过开一个数组(例如我的b[][]数组) 用了存储到当前位置剩余最大 ...

  8. Python快速入门

    Python快速入门 一.基础概要 命名:h.py Linux命令行运行:python h.py 注释.数字.字符串: 基本类型只有数字与字符串 #python注释是这样写的 ''' 当然也可以这样 ...

  9. Book Lending Registration

    <!DOCTYPE HTML> <HTML lang="|en"> <head> <meta charset="UTF-8&qu ...

  10. 工程管理之makefile与自动创建makefile文件过程

    (风雪之隅 http://www.laruence.com/2009/11/18/1154.html) Linux Makefile自动编译和链接使用的环境 想知道到Linux Makefile系统的 ...