Solve the problem of blank gap at the bottom of Img picture

Solve the problem of blank gap at the bottom of Img picture

When working on a recent project, I found that there was always a blank space below when referencing pictures, as shown in the figure below.

<style>
    .img-box {
        border: 2px solid red;
        width: 550px;
    }
</style>

<div class="img-box">
    <img src="./img.png" alt="">
</div>

Later I found out that the reason is that the inline block elements will be aligned with the text baseline. To solve this problem is actually very simple, there are two main methods:

1. Add vertical-align: middle | top | bottom, etc. to the image. (Recommended)

img {
    vertical-align: bottom;
}

2. Convert the image to a block-level element display: block; (Converting block-level elements may affect your layout, so the first method is recommended)

g {
    display: block;
} 

Well, the problem is solved so simply.
If you have any better methods, please feel free to share and leave a message in the comment area.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Vue custom directive details

>>:  MySQL data table partitioning strategy and advantages and disadvantages analysis

Recommend

CSS3 animation – steps function explained

When I was looking at some CSS3 animation source ...

How to install Docker on Windows Server 2016

Recently Microsoft released Windows Server 2016, ...

Sample code for CSS image animation effects (photo frame)

This article introduces the sample code of CSS pi...

Vue3.0+vite2 implements dynamic asynchronous component lazy loading

Table of contents Create a Vite project Creating ...

Various correct postures for using environment variables in Webpack

Table of contents Write in front Business code us...

Detailed explanation of Vue3 life cycle functions and methods

1. Overview The so-called life cycle function is ...

Mini Program to implement Token generation and verification

Table of contents process Demo Mini Program Backe...

How to automatically deploy Linux system using PXE

Table of contents Background Configuring DHCP Edi...

Advantages and disadvantages of conditional comments in IE

IE's conditional comments are a proprietary (...

How to write high-quality JavaScript code

Table of contents 1. Easy to read code 1. Unified...

Detailed explanation of the implementation of shared modules in Angular projects

Table of contents 1. Shared CommonModule 2. Share...

Jmeter connects to the database process diagram

1. Download the MySQL jdbc driver (mysql-connecto...