对于损坏的图像,是否在任何地方指定浏览器应该遵守 width/height attributes/CSS 还是将它们视为替换元素?

For broken images, is it specified anywhere whether browsers are supposed to obey width/height attributes/CSS or consider them replaced elements?

我注意到当 display:inline 图像损坏时,浏览器之间的行为非常不同。当图像损坏时,是否应该有任何标准行为,至少在是否仍然遵守宽度和高度(HTML 属性或 CSS)方面,以及元素是否仍被视为替换元素?

https://html.spec.whatwg.org/multipage/images.html#img-error 似乎没有定义这个。有什么补充的地方吗?自从最早的图形浏览器以来,我已经习惯了不同的浏览器具有不同的损坏图像图标之类的东西,但我认为现在至少会在某处指定与布局相关的东西。不是这样吗?

当src为404ed时,有alt属性,display保留为默认(内联):

我在下面损坏的图片中注意到的其他内容:

(没有 alt 属性的图像实际上无效 HTML,但显示是为了比较行为。)

在 Chrome 64、Firefox 58、Safari 11、EdgeHTML 16.16299

中测试

img{
  border:1px solid black;
  margin:1em;
  padding:1em;
}

.force-ib-images img{
  display:inline-block;
}
<img src="x" width="300" height="120" alt="alttext"> (alt="alttext") <br>
<img src="x" width="300" height="120" alt=""         > (alt="")<br>
<img src="x" width="300" height="120" alt            > (alt)<br>
<img src="x" width="300" height="120"                > (no alt attribute)<br>

<hr>

<h3>
  with height/width set via css:
</h3>

<img src="x" style="width:300px; height:120px" alt="alttext"> (alt="alttext") <br>
<img src="x" style="width:300px; height:120px" alt=""         > (alt="")<br>
<img src="x" style="width:300px; height:120px" alt            > (alt)<br>
<img src="x" style="width:300px; height:120px"                > (no alt attribute)<br>

<hr>

<div class="force-ib-images">

  <h3>
    Forced inline-block:
  </h3>

  <img src="x" style="width:300px; height:120px" alt="alttext"> (alt="alttext") <br>
  <img src="x" style="width:300px; height:120px" alt=""         > (alt="")<br>
  <img src="x" style="width:300px; height:120px" alt            > (alt)<br>
  <img src="x" style="width:300px; height:120px"                > (no alt attribute)<br>

</div>


<hr>

  <h3>
    With image:
  </h3>

<img src="https://i.imgur.com/FQFzBJh.png" width="300" height="120" alt="an image">

JSFiddle:https://jsfiddle.net/upkt6p7p/

来自 HTML 5.3 10.4.2 Images: (WHATWG)

If the element is an img element that represents some text and the user agent does not expect this to change

The user agent is expected to treat the element as a non-replaced phrasing element whose content is the text, optionally with an icon indicating that an image is missing, so that the user can request the image be displayed or investigate why it is not rendering. In non-graphical contexts, such an icon should be omitted.

所以图片破损时应该是non-replaced元素

但请注意,浏览器不必遵守第 10 节。"is expected" 表示浏览器仅在声明遵守时才需要遵守。

User agents are not required to present HTML documents in any particular way. However, this section provides a set of suggestions for rendering HTML documents that, if followed, are likely to lead to a user experience that closely resembles the experience intended by the documents' authors. [...] For the purposes of conformance for user agents designated as supporting the suggested default rendering, the term "expected" in this section has the same conformance implications as "must". (10 Rendering)(WHATWG)