White space at bottom of anchor tag

HtmlCssXhtml

Html Problem Overview


Html Solutions


Solution 1 - Html

The image is display: inline so it is treated like a character and sits on the baseline. The gap is caused by the space provided for the descender (which you find on letters like j, g, y and p).

Adjust the vertical-align with CSS: img{vertical-align: bottom}

Solution 2 - Html

display:block is sufficient for this, if the element has no siblings.

Solution 3 - Html

I had the same issue and i fixed it by adding to the 'a' tag display: block; and font-size: 0px;

Solution 4 - Html

I fixed mine by adding

a {
 display:inherit
}

Hope this helps

Solution 5 - Html

December 2021 Solution

As announced by several people, css :has() selector was implemented. So this issue could be solved for anchors which "has" images as a direct child:

a:has(> img) {
  font-size: 0;
}

At the moment I am writing this reply, it is only supported by Safari TP but probably this table will be greener soon.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIcode4foodView Question on Stackoverflow
Solution 1 - HtmlQuentinView Answer on Stackoverflow
Solution 2 - Htmlmeder omuralievView Answer on Stackoverflow
Solution 3 - HtmlchristkView Answer on Stackoverflow
Solution 4 - HtmlMarc OrdinarioView Answer on Stackoverflow
Solution 5 - HtmlLionel TView Answer on Stackoverflow