Forum Moderators: not2easy

Message Too Old, No Replies

Image within a div has a gap on the bottom

         

markwm

4:14 pm on Mar 4, 2007 (gmt 0)

10+ Year Member



I have this very simple code:

<style type="text/css">
#mydiv {
background-color: red;
}
</style>

<div id="mydiv"><img src="images/ad.jpg" width="150" height="180"></div>

For some reason in Safari, Opera and Firefox I can see 3px of red below the image, yet in IE 6/Win there is none.

Adding a margin-bottom: 0px to the image doesn't fix it. Why exactly does their appear to be a 3px margin underneath my image?

DanA

6:03 pm on Mar 4, 2007 (gmt 0)

10+ Year Member



Without seeing your entire HTML and CSS, it's quite hard to help you

Ingolemo

6:33 pm on Mar 4, 2007 (gmt 0)

10+ Year Member



I suspect this is caused by the fact that images aren't block elements; they're inline. The 3 or so pixels at the bottom are the bits below the baseline where text descenders would usually go (the tails on letters like g).

If that is indeed the problem, then you should be able to fix it by setting

display:block;
on the img.

Setek

3:46 am on Mar 6, 2007 (gmt 0)

10+ Year Member



I suspect this is caused by the fact that images aren't block elements; they're inline. The 3 or so pixels at the bottom are the bits below the baseline where text descenders would usually go (the tails on letters like g).

If that is indeed the problem, then you should be able to fix it by setting display:block; on the img.

Yes, and this I believe only happens with a correct and full doctype - without it, images by default are vertically aligned at bottom.

If adding

display: block;
to every image is not suitable, you could also add
vertical-align: bottom;
to the images, which I believe is a less intrusive solution.