Home > Web Front-end > CSS Tutorial > Why Does an Anchor Tag Add Whitespace Below an Image in a Bordered Div?

Why Does an Anchor Tag Add Whitespace Below an Image in a Bordered Div?

Susan Sarandon
Release: 2024-12-15 09:34:10
Original
500 people have browsed it

Why Does an Anchor Tag Add Whitespace Below an Image in a Bordered Div?

Anchor Tag Adds White Space Below Image

When an anchor tag encloses an image within a bordered div, an unexpected gap may appear beneath the image. This issue stems from the inline display property of the image, treating it as a character positioned on the baseline. The gap accommodates descenders found in typography, like "j" or "g."

To resolve this, adjust the vertical alignment of the image using CSS:

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

This code forces the bottom of the image to align with the baseline, eliminating the white space and restoring the desired design.

The above is the detailed content of Why Does an Anchor Tag Add Whitespace Below an Image in a Bordered Div?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template