帝王谷资源网 Design By www.wdxyy.com

问题描述

按钮样式为图标+文字,在使用flex布局写垂直居中时,iphone7手机上文字和图标却没有居中,居左显示。代码如下(已精简):

<button>
  <img src="./refresh.png" alt />
  {{ confirmButtonText }}
</button>

...
button {
  display: flex;
  align-items: center;
  justify-content: center;
  img {
      width: 36px;
      height: 36px;
      display: inline-block;
  }
}

预期样式:

button内flex垂直居中竟然不居中的解决

实际样式:

button内flex垂直居中竟然不居中的解决

解决方式

给icon和文字外再包一层标签,给外层标签设置flex垂直居中样式,代码如下:

<button>
  <span class="wrap">
     <img src="./refresh.png" alt />
      {{ confirmButtonText }}
  </span>
</button>

...
button {
   display: flex;
   align-items: center;
   justify-content: center;
  .wrap {
      img {
          width: 36px;
          height: 36px;
          display: inline-block;
      }
  }
}

标签:
button,flex垂直居中,不居中

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com