微信小程序:flex常用布局

在我们平时微信小程序开发过程中为了页面能达到设计小伙伴的预期,追求还原度,那我们肯定会使用很多常用的布局方式,那我们今天就介绍一下微信小程序中常用的一些flex布局

1、常用flex布局

复制代码
/** 水平垂直居中 **/
.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

/** 纵向依次排列 **/
.direction-column {
  flex-direction: column;
}

/** 平分,一左一右排列 **/
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/** 从左往右垂直居中依次排列 **/
.flex-start {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

/** 从右往左垂直居中依次排列 **/
.flex-end {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/** 从左往右依次排列,底部(基线)对齐 **/
.flex-start-base {
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
}

2、其它布局

order属性定义项目的排列顺序。数值越小,排列越靠前,默认为0

复制代码
.item{
  order: <integer>;
}

flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。

复制代码
.item {
  flex-grow: <number>; /* default 0 */
}

flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。

复制代码
.item {
  flex-shrink: <number>; /* default 1 */
}
相关推荐
游戏开发爱好者812 分钟前
苹果 App 上架流程,结合 Xcode、CI 等常见工具
macos·ios·ci/cd·小程序·uni-app·iphone·xcode
前端老白25 分钟前
webview在微信小程序中,安卓加载失败,IOS正常加载
android·ios·微信小程序·webview
2501_9151063226 分钟前
用 HBuilder 上架 iOS 应用时如何管理Bundle ID、证书与描述文件
android·ios·小程序·https·uni-app·iphone·webview
2501_9159090636 分钟前
资源文件混淆在 iOS 应用安全中的实际价值
android·安全·ios·小程序·uni-app·iphone·webview
2501_9159184136 分钟前
iOS App 性能测试中常被忽略的运行期问题
android·ios·小程序·https·uni-app·iphone·webview
多仔ヾ1 小时前
微信小程序开发实战之 03-微信小程序页面交互
微信小程序
狮子也疯狂1 小时前
【鸿蒙小程序】| 鸿蒙系统中的元服务创新与实践
小程序·notepad++·harmonyos
汝生淮南吾在北16 小时前
SpringBoot3+Vue3小区物业报修系统+微信小程序
微信小程序·小程序·vue·毕业设计·springboot·课程设计·毕设
静待雨落16 小时前
如何在Taro项目中使用axios
微信小程序·taro
前端小黑屋17 小时前
小程序直播挂件Pendant问题
前端·微信小程序·直播