Imagine three images with fixed size:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div.photos img {
width: 320px;
height: 240px;
background-color: black;
}
</style>
</head>
<body>
<div class="photos">
<img src="abc" />
<img src="def" />
<img src="ghi" />
</div>
</body>
</html>
When you look at such page in IE or Chrome, you’ll see what I expected – threee images with fixed sizes.
In Firefox however, it doesn’t work.
But if I set the images to display: block; or remove the DOCTYPE (doesn’t show on jsfiddle) it works.
What am I doing wrong?
Thanks
This seems to be an old feature in Firefox: I found a discussion about it from year 2007:
So I suppose it’s intentional and won’t go away. I guess they might be thinking this way: Everything is fine if you set dimensions on an image, we’ll scale it. But if the image is missing, we will render the alternative text instead, and this changes the
imgelement from a replaced inline element to a text, a non-replaced inline element, and for it we won’t supportheightandwidth, by the spec. Instead, the text determines the dimensions. And presumably the authors of Firefox think this is the right thing to do, and only in Quirks Mdoe do they do as other browsers do.If you add
altattributes (as you should, everyimgshould have one), you’ll see how the box size varies by text length. Apparently Firefox treats a missingalthere as equivalent toalt="", implying zero width.This would explain why setting
displaytoinline-block(orblock) changes the behavior: thenwidthandheightare applied.