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

1 <view class="grid">
2 <view class='item1'>1</view>
3 <!-- <view class='item'>2</view>
4 <view class='item'>3</view>
5 <view class='item'>4</view>
6 <view class='item'>5</view>
7 <view class='item'>6</view>
8 <view class='item'>7</view>
9 <view class='item'>8</view>
10 <view class='item'>9</view> -->
11 </view>

1 page {
2 color: #fff;
3 font-size: 16px;
4 }
5
6 .grid {
7 /* padding: 1%; */
8 display: grid;
9 grid-template-rows: 80px 80px;
10 grid-template-columns: 1fr 1fr;
11 grid-template-areas: "content content" "content content";
12 border: 1px solid #ccc;
13 }
14
15 .grid {
16 justify-items: start;
17 /* justify-items: end; */
18 /* justify-items: center; */
19 /* justify-items: stretch; */
20 }
21
22 .item1 {
23 grid-area: content;
24 display: flex;
25 align-items: center;
26 justify-content: center;
27 border: 1px solid #fff;
28 border-radius: 0.2rem;
29 font-size: 0.8em;
30 min-height: 3rem;
31 padding: 0.75rem;
32 color: #f0f0f3;
33 /* background-color: #e91e63; */
34 }
35
36 .item {
37 text-align: center;
38 background-color: #d94a6a;
39 }
40
41 .item1 {
42 /* text-align: center; */
43 background-color: #1aa034;
44 }
justify-items
和justify-self
指定网格项目沿着行轴对齐方式;align-items
和align-self
指定网格项目沿着列轴对齐方式。
justify-items
和align-items
应用在网格容器上,它们的属性值有:
auto
normal
start
end
center
stretch
baseline
first baseline
last baseline
1. justify-items
stretch
2. align-items
align-items: stretch(网格项目横跨整个列)
网格项目定位在网格行和列的中间(实现水平垂直居中)。

1 <view class="grid"> 2 <view class='item1'>1</view> 3 <!-- <view class='item'>2</view> 4 <view class='item'>3</view> 5 <view class='item'>4</view> 6 <view class='item'>5</view> 7 <view class='item'>6</view> 8 <view class='item'>7</view> 9 <view class='item'>8</view> 10 <view class='item'>9</view> --> 11 </view>

1 page { 2 color: #fff; 3 font-size: 16px; 4 } 5 6 .grid { 7 /* padding: 1%; */ 8 display: grid; 9 grid-template-rows: 80px 80px; 10 grid-template-columns: 1fr 1fr; 11 grid-template-areas: "content content" "content content"; 12 border: 1px solid #ccc; 13 } 14 15 .grid { 16 justify-items: center; 17 align-items: center; 18 /* align-items: start; */ 19 /* align-items: center; */ 20 /* align-items: end; */ 21 /* justify-items: start; */ 22 /* justify-items: end; */ 23 /* justify-items: center; */ 24 /* justify-items: stretch; */ 25 } 26 27 .item1 { 28 grid-area: content; 29 display: flex; 30 align-items: center; 31 justify-content: center; 32 border: 1px solid #fff; 33 border-radius: 0.2rem; 34 font-size: 0.8em; 35 min-height: 3rem; 36 padding: 0.75rem; 37 color: #f0f0f3; 38 /* background-color: #e91e63; */ 39 } 40 41 .item { 42 text-align: center; 43 background-color: #d94a6a; 44 } 45 46 .item1 { 47 /* text-align: center; */ 48 background-color: #1aa034; 49 }
1 2 | justify-items: center ; align-items: center ; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2018-04-09 javascript原生调用摄像头
2018-04-09 网页背景图片随机
2018-04-09 网页背景视频的实现