微信小程序元素水平居中或垂直居中

.wxml

<view class="father">
<view class="children1">子元素1</view>
<view class="children2">子元素2</view>
<view class="children3">子元素3</view>
</view>
.wxss

.father{
    display: flex;
    align-items: center;
    height: 100rpx;
    background-color: #00ff00;
}
.children1{
    background-color: #ff004c;
}
.children2{
    background-color: #c6c4cc;
}
.children3{
    background-color: #eeff00;
}

一、水平居中

1、排列方向为水平方向
.father{

display: flex;

align-items: center;

height: 100rpx;

background-color: #00ff00;


}

 

2、排列方向为竖直方向
.father{

display: flex;

flex-direction: column;

align-items: center;

background-color: #00ff00;

overflow: hidden;


}

 

 二、垂直居中
1、排列方向为水平方向
.father{

display: flex;

flex-direction:column;

justify-content: center;

background-color: #00ff00;


}

2、排列方向为竖直方向
.father{

display: flex;

justify-content: center;

background-color: #00ff00;


father的高度等于最大item的高度

 

三、中心居中
1、排列方向为水平方向
.father{

display: flex;

align-items: center;

justify-content: center;

background-color: #00ff00;


 2、排列方向为竖直方向
.father{

display: flex;

flex-direction: column;

align-items: center;

justify-content: center;

background-color: #00ff00;


}

 微信小程序元素水平居中或垂直居中_qq_33880604的博客-CSDN博客_小程序居中

  • 17
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值