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

最近在做一个微信小程序的项目,其中涉及到css样式实现将<navigator>标签内的图片和文本元素垂直排列,并水平居中。在尝试实现的过程中,将元素在标签内的所有排列情况都顺带实现了。上代码:

index.wxml

javascript 复制代码
<navigator url="/pages/user/user-collect/index" hover-class="none" class="user-navigator">
    <image class="order-image" src="/public/img/5-8.png"></image>
    <text class="text-black user-text">收藏</text>
</navigator>

index.wxss

javascript 复制代码
.user-text {
  padding: 10% 0%;
}

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

顺带实现的其他排列情况index.wxss文件中的对用内容如下:

一、水平居中

javascript 复制代码
1、排列方向为水平方向
.user-navigator{
  display: flex;
  align-items: center;
}
2、排列方向为竖直方向
.user-navigator{
  display: flex;
  flex-direction: column;
  align-items: center;
}

二、垂直居中

javascript 复制代码
1、排列方向为水平方向
.user-navigator{
  display: flex;
  flex-direction:column;
  justify-content: center;
}
2、排列方向为竖直方向
.user-navigator{
  display: flex;
 justify-content: center;
}

三、中心居中

javascript 复制代码
1、排列方向为水平方向
.user-navigator{
  display: flex;
  align-items: center;
  justify-content: center;
}
2、排列方向为竖直方向
.user-navigator{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
相关推荐
土土哥V_araolin1 小时前
双迪大健康新零售系统开发要点
小程序·个人开发·零售
2501_915909063 小时前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
CHU7290355 小时前
扭蛋机盲盒小程序前端功能设计及核心玩法介绍
前端·小程序
职豚求职小程序6 小时前
中华财险笔试测评题库小程序刷题职豚2026新
小程序
阿珊和她的猫6 小时前
小程序双线程架构:逻辑层与视图层的协同运作机制
小程序·架构
源码ym7k资源6 小时前
在线家政系统(APP+小程序)源码:为您提供专业的本地服务
小程序
2601_952013766 小时前
家政服务小程序预约上门服务维修保洁上门服务在线派单技师入驻-ym7K
小程序
2501_915921436 小时前
常用iOS性能测试工具大全及使用指南
android·测试工具·ios·小程序·uni-app·cocoa·iphone
一字白首7 小时前
小程序组件化进阶:从复用到通信的完整指南DAY04
前端·小程序·apache
是Winky啊7 小时前
【逆向+爬虫】获取小程序信息
小程序