当前位置:主页 > 查看内容

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

发布时间:2021-04-21 00:00| 位朋友查看

简介:问题描述 按钮样式为图标+文字,在使用flex布局写垂直居中时,iphone7手机上文字和图标却没有居中,居左显示。代码如下(已精简): button img src=./refresh.png alt / {{ confirmButtonText }}/button...button { display: flex; align-items: center; ju……

问题描述

按钮样式为图标+文字,在使用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;
  }
}

预期样式:

实际样式:

解决方式

给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垂直居中竟然不居中的解决的文章就介绍到这了,更多相关button内flex垂直居中不居中内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!


原文链接:https://m.jb51.net/css/749796.html
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:详解css盒子模型之内边距padding及简写 下一篇:没有了

推荐图文


随机推荐