Home > Article > Web Front-end > Why Is There Space Below My Inline-Block Image and How Do I Fix It?
Resolving Space Underneath Inline-Block Images
In your code example, you attempt to display an image inline with the text using the display: inline-block property, but notice an unwanted space below the image. To address this, let's delve into the causes and a comprehensive solution.
The line break that follows the image element creates the space because inline elements naturally reserve space below them for potential text content. Since the image doesn't have any text content, this space remains unoccupied and appears as an unwanted gap.
To eliminate this space, we need to eliminate the line break. One way to achieve this is by setting the vertical-align property to top for the image. This will vertically align the top of the image with the baseline of the surrounding text.
<code class="CSS">img { display: inline-block; margin: 0; vertical-align: top; }</code>
With this adjustment, the space below the image disappears, allowing the image to sit flush with the surrounding content. You can verify this by modifying your code in the provided fiddle: http://jsfiddle.net/dJVxb/4/.
The above is the detailed content of Why Is There Space Below My Inline-Block Image and How Do I Fix It?. For more information, please follow other related articles on the PHP Chinese website!