欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > 微信小程序元素水平居中或垂直居中

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

2025/5/2 6:57:17 来源:https://blog.csdn.net/sinat_41617212/article/details/143370915  浏览:    关键词:微信小程序元素水平居中或垂直居中

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

index.wxml

<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

.user-text {padding: 10% 0%;
}.user-navigator {display:flex;flex-direction: column;align-items: center;
}

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

一、水平居中

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

二、垂直居中


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

三、中心居中

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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词