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

最近在做一个微信小程序的项目,其中涉及到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;
}
相关推荐
大米饭消灭者2 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro
FliPPeDround3 天前
Vitest Environment UniApp:让 uni-app E2E 测试变得前所未有的简单
微信小程序·e2e·前端工程化
FliPPeDround3 天前
微信小程序自动化的 AI 新时代:wechat-devtools-mcp 智能方案
微信小程序·ai编程·mcp
吴声子夜歌3 天前
小程序——布局示例
小程序
码云数智-大飞3 天前
如何创建自己的小程序,码云数智与有赞平台对比
微信小程序
luffy54593 天前
微信小程序页面使用类似filter函数的wxs语法
微信小程序·小程序
Slow菜鸟3 天前
微信小程序开发(二)目录结构完全指南
微信小程序·小程序
攀登的牵牛花3 天前
给女朋友写了个轻断食小程序:去老丈人家也是先动筷了
前端·微信小程序
前端小雪的博客.3 天前
【保姆级教程】uniAI 插件高效开发 uni-app 微信小程序(附实战案例)
微信小程序·uni-app·ai编程·uniai
小小王app小程序开发3 天前
海外盲盒小程序抽赏玩法分析(附跨境技术落地要点)
小程序