關於小程序中控件居中

使View組件居中的方法

1.將view組件設置

display:flex;
justify-content: center;

給個水平居中的實例
水平居中
tig:如果實現不了垂直居中,將view設爲父控件,將子控件的佈局設爲絕對佈局
在這裏插入圖片描述

position: absolute;

然後設置高度定位top: 450rpx;

做之前也上網查找過資料,網上關於垂直居中還有一種說法就是
display:flex; justify-content: center; align-items: center;
我自己實測的時候align-items:center並不起作用,希望有知道的大神能幫忙解惑一下。

wxml:

<view class="userinfo">
        <text class="userinfo-role" >認證等級</text>
</view>

wxss:

.userinfo {
  display: flex;
  justify-content: center;
}
.userinfo-role {
  position: absolute;
  top: 450rpx;
}

2.使用margin: 0 auto;效果圖和方法1一樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章