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

最近在做一个微信小程序的项目,其中涉及到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 小时前
私域直播小程序源码的整体架构设计与实现思路
学习·小程序
ee82ee2 小时前
uniapp小程序底部键盘唤起问题处理,包含间隙处理,动画处理
微信小程序
qq_12498707533 小时前
基于springboot健康养老APP的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·mysql·微信小程序·毕业设计
汤姆yu3 小时前
基于微信小程序的驾校预约与学习系统
学习·小程序·驾校预约
夏源4 小时前
【微信小程序】实现引入 Echarts 并实现更新数据
微信小程序
speedoooo5 小时前
未来的App不再需要菜单栏?
前端·ui·容器·小程序·web app
猿究院_xyz5 小时前
微信小程序与echarts联动安卓真机测试出现黑色阴影
前端·javascript·微信小程序·小程序·echarts
说私域6 小时前
不同类型企业构建私域流量的必要性及定制开发AI智能名片商城小程序的应用
大数据·人工智能·小程序
老华带你飞7 小时前
健身房预约|基于springboot 健身房预约小程序系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·小程序
2501_915909067 小时前
苹果应用加密方案的一种方法,在没有源码的前提下,如何处理 IPA 的安全问题
android·安全·ios·小程序·uni-app·iphone·webview