I thought I understood how inline and block elements work, however this has thrown me. I have found a fix for the issue however I have no idea why it works.
For some reason if you have an img
inside a div
, the div is like 3.5px
taller than the image. However if you set the image as a block element this extra height disappears.
Basic HTML:
<div id="wrapper">
<img src="http://www.basini.com/wp-content/uploads/2013/02/seeing-in-the-dark.jpg" width="300" height="230" />
</div>
And the CSS:
#wrapper {
background: orange;
}
#wrapper img {
/* display: block; this will remove the extra height */
}
I have set up a jsfiddle to demonstrate the effect
Why does this happen and why does making the 'img' a block element fix it? Are there any other solutions?