Home > Web Front-end > CSS Tutorial > How to solve the problem of blank gap at the bottom of the picture with css

How to solve the problem of blank gap at the bottom of the picture with css

王林
Release: 2020-04-17 09:08:25
forward
2983 people have browsed it

How to solve the problem of blank gap at the bottom of the picture with css

Problem description:

There is always a blank space below when quoting pictures, as shown in the figure below.

How to solve the problem of blank gap at the bottom of the picture with css

css code:

<style>
    .img-box {
        border: 2px solid red;
        width: 550px;
    }
</style>
<div class="img-box">
    <img src="./img.png" alt="">
</div>
Copy after login

Cause analysis:

Inline block elements will be aligned with the baseline of the text.

(Recommended tutorial: CSS tutorial)

Solution:

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

img {
    vertical-align: bottom;
}
Copy after login

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

g {
    display: block;
}
Copy after login

Recommended related video tutorials: css video tutorial

The above is the detailed content of How to solve the problem of blank gap at the bottom of the picture with css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template