微信小程序Flex居中布局示例

所有示例以此 wxml 为基础

<view class='boxs'>
  <view class='box'></view>
  <view class='box'></view>
  <view class='box'></view>
</view>

.box{
  width: 200rpx;
  height: 200rpx;
  background: greenyellow;
  margin-right: 10rpx;
}

各位理解能力比较强的可以先理解一下这张图,就会对flex布局有更进一步的理解:

弹性盒

 

一、水平居中

1、排列方向为水平方向

.boxs{
  display: flex;
  align-items: center;
}

2、排列方向为竖直方向

.boxs{
  display: flex;
  flex-direction: column;
  align-items: center;
}

 

二、垂直居中

1、排列方向为水平方向

.boxs{
  display: flex;
  flex-direction:column;
  justify-content: center;
}

2、排列方向为竖直方向

.boxs{
  display: flex;
  justify-content: center;
}

 

三、中心居中

1、排列方向为水平方向

.boxs{
  display: flex;
  align-items: center;
  justify-content: center;
}

2、排列方向为竖直方向

.boxs{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值