I have encountered a unique scenario where I want to set a pre-determined height for an HTML img
element before it finishes loading. This is crucial because this height will be utilized in a calculation that may occur before the image is completely loaded, and accuracy is essential. I attempted the following approach:
<div>hello<img src='http://example.com/invalid.gif' class="testimage"> there</div>
and then added some CSS rules:
.testimage {
height: 200px;
width: 200px;
}
Surprisingly, in Firefox 5, the additional space is not displayed (and interestingly, the broken image is not shown either – just a blank space). However, when I include display: inline-block
, the extra space does appear. It seems that other browsers render correctly with the default display of inline
. Is this behavior expected? If so, what is the reason behind it?
You can also view a jsFiddle demonstration here: http://jsfiddle.net/uYXD4/