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

How to install and modify the initial password of mysql5.7.18

For Centos installation of MySQL, please refer to...

Specific usage of textarea's disabled and readonly attributes

disabled definition and usage The disabled attrib...

Summary of Mysql-connector-java driver version issues

Mysql-connector-java driver version problem Since...

Detailed explanation of docker-machine usage

Docker-machine is a Docker management tool offici...

Import csv file into mysql using navicat

This article shares the specific code for importi...

MySQL compressed package version zip installation configuration method

There are some problems with the compressed versi...

How to use VUE and Canvas to implement a Thunder Fighter typing game

Today we are going to implement a Thunder Fighter...

Ubuntu 20.04 firewall settings simple tutorial (novice)

Preface In today's increasingly convenient In...

We're driving IE6 to extinction on our own

In fact, we wonder every day when IE6 will really...

Use Firebug tool to debug the page on iPad

How to debug a page on iPad? When using iOS 5, you...

uni-app implements NFC reading function

This article shares the specific code of uni-app ...

MySQL 8.0.18 deployment and installation tutorial under Windows 7

1. Preliminary preparation (windows7+mysql-8.0.18...