Solution to the problem that the vertical centering of flex inside button is not centered

Solution to the problem that the vertical centering of flex inside button is not centered

Problem Description

The button style is icon + text. When using flex layout to vertically center it, the text and icon are not centered on the iPhone 7 phone, but displayed on the left. The code is as follows (simplified):

<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;
  }
}

Expected style:

Actual style:

Solution

Wrap another layer of labels around the icon and text, and set the flex vertical center style for the outer label. The code is as follows:

<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;
      }
  }
}

This is the end of this article about how to solve the problem of flex vertical centering inside button not being centered. For more information about flex vertical centering inside button not being centered, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Practice of using Tinymce rich text to customize toolbar buttons in Vue

>>:  A Brief Analysis of Patroni in Docker Containers

Recommend

Sqoop export map100% reduce0% stuck in various reasons and solutions

I call this kind of bug a typical "Hamlet&qu...

Solve the problem that PhpStorm fails to connect to VirtualBox

Problem description: When phpstorm's SFTP hos...

Overview of the definition of HTC components after IE5.0

Before the release of Microsoft IE 5.0, the bigges...

How to deploy SpringBoot project using Docker

The development of Docker technology provides a m...

Detailed explanation of storage engine in MySQL

MySQL storage engine overview What is a storage e...

Analyzing Linux high-performance network IO and Reactor model

Table of contents 1. Introduction to basic concep...

Detailed explanation of using Vue.prototype in Vue

Table of contents 1. Basic Example 2. Set the sco...

Solution to the problem of eight hours difference in MySQL insertion time

Solve the problem of eight hours time difference ...

Understanding v-bind in vue

Table of contents 1. Analysis of key source code ...

The iframe refresh method is more convenient

How to refresh iframe 1. To refresh, you can use j...

CSS writing format, detailed explanation of the basic structure of a mobile page

1. CSS writing format 1. Inline styles You can wr...