使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一樣