如何让view内的文字居中对齐?
发布于 5 年前 作者 xiayin 5877 次浏览 来自 问答

比如:

<view style=“height:40px; width:100px; background-color:yellow”>文字</view>

我希望文字能在放置在view的中间位置(目前是靠左对齐),如何实现?

2 回复

官方推荐使用flex布局:

.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}

你可以设置flex和align-items即可

text-align:center;文本居中对齐你没有加?

回到顶部