Let me first explain why the text is not vertically centered when line-height is equal to the element height. In fact, when line-height is equal to the element height, the text is not really centered, but looks centered. When the difference between the element height and font-size is large, this is more and more obvious. Here you can refer to What is a baseline? The green line in the image below is the baseline: line-height refers to the distance between two lines of text [baseline] Solution 1: Combining line height, alignment and pseudo elements .text{ width: 16px; height: 16px; font-size: 10px; text-align: center; } .text::after{ content: ' '; display: inline-block; width: 0; height: 100%; vertical-align: middle; margin-top: 1px; } Solution 2: Use the CSS3 scale property to set all values to double the size and then double the size. .text{ width: 32px; height: 32px; line-height: 32px; font-size: 20px; text-align: center; transform: scale(0.5); } This is the end of this article about solving the problem of line-height=height element height but text is not vertically centered. For more relevant content about line-height=height element height, 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! |
<<: CSS code abbreviation div+css layout code abbreviation specification
>>: Introduction to the application of HTML tags superscript sup and subscript sub
1. Problem Description Today I need to check the ...
First, let's talk about why we use provide/in...
This article example shares the specific code of ...
Table of contents Writing Background Project Desc...
Table of contents Preface start A little thought ...
1. Tools We need two tools now: MySQL server (mys...
Table of contents Union query 1. Query the ID and...
Bugs As shown in the figure, I started to copy th...
MySQL trigger simple example grammar CREATE TRIGG...
The team replaced the new frame. All new business...
This article shares the specific code of Vue3 man...
This article shares the detailed steps of install...
Preface To delete a table, the command that comes...
1. Pull the image docker pull registry.cn-hangzho...
Table of contents 1. Usage 2. Output results 1.id...