当前位置:   article > 正文

小程序view容器中文字上下居中、左右居中显示_view文字居中

view文字居中

方法一、text-align、line-height

其中line-height的值必须等于容器的高度值。

  1. .wxml
  2. <view class='text_align' >水平居中</view>
  3. <view class='line_height' >垂直居中</view>
  4. <view class='center' >水平居中||垂直居中</view>
  5. .wxss
  6. .text_align{
  7. width: 350rpx;
  8. height: 350rpx;
  9. background-color: gray;
  10. text-align: center; /** 水平居中 **/
  11. }
  12. .line_height{
  13. width: 350rpx;
  14. height: 350rpx;
  15. background-color: orange;
  16. line-height: 350rpx; /** 垂直居中 **/
  17. }
  18. .center{
  19. width: 350rpx;
  20. height: 350rpx;
  21. background-color: brown;
  22. line-height: 350rpx; /** 垂直居中 **/
  23. text-align: center; /** 水平居中 **/
  24. }

效果图如下:

 

方法二、display flexible box模型

  1. .wxml
  2. <view class='text_align' >水平居中</view>
  3. <view class='line_height' >垂直居中</view>
  4. <view class='center' >水平居中||垂直居中</view>
  5. .wxss
  6. .text_align{
  7. width: 350rpx;
  8. height: 350rpx;
  9. background-color: gray;
  10. display: flex;
  11. flex-direction: column;
  12. justify-content: center;
  13. align-items: center;
  14. }
  15. .line_height{
  16. width: 350rpx;
  17. height: 350rpx;
  18. background-color: orange;
  19. line-height: 350rpx; /** 垂直居中 **/
  20. }
  21. .center{
  22. width: 350rpx;
  23. height: 350rpx;
  24. background-color: brown;
  25. line-height: 350rpx; /** 垂直居中 **/
  26. text-align: center; /** 水平居中 **/
  27. }

效果图:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/460120
推荐阅读
相关标签
  

闽ICP备14008679号