tags:

views:

22

answers:

2

I have an tag surrounding an image. I have a border set on the div that the tag is in. I have both margin and padding set to 0 but for some reason my tag is still about 3 pixels taller than my image. This leaves a bit of space between the image and the border, which destroys the look that I want to accomplish.

What am I doing wrong? I have tested in both FireFox and Chrome with the same results. Thanks

+1  A: 

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.

David Dorward
More specifically, `img{vertical-align: bottom}`
Álvaro G. Vicario
That is exactly what is happening. The issue is resolved if I do `vertical-align:bottom;` or `display:block;`. Which is the better solution?
Icode4food
Neither is better, they just have different implications. Block elements have line breaking around them and other fun side effects.
David Dorward
A: 

http://work.arounds.org/mysterious-white-space-gap-under-image-elements/

display:block is sufficient for this if it has no siblings.

meder
Interesting, so the real culprit is the image tag, not the <a> tag.
Icode4food
That is what David pretty much said, any inline element will have space for descenders. It's the natural behavior.
meder