好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

问题描述

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

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

 .. .
button {
  dis play : flex;
  align -i tems:  center ;
  justify-content: center;
  img {
      width: 36px;
      h ei ght: 36px;
      display: inline-block;
  }
}

预期样式:

实际样式:

解决方式

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

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

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

到此这篇关于button内flex垂直居中竟然不居中的解决的 文章 就介绍到这了,更多相关button内flex垂直居中不居中内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!

总结

以上是 为你收集整理的 button内flex垂直居中竟然不居中的解决 全部内容,希望文章能够帮你解决 button内flex垂直居中竟然不居中的解决 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于button内flex垂直居中竟然不居中的解决的详细内容...

  阅读:35次