html中图片不可用如何处理,HTML – 当img无法显示时应该发生什么?

  • Post author:
  • Post category:其他


似乎没有严格的规则. HTML规范仅描述了浏览器的行为方式,但对浏览器没有规定要求遵循上述行为的规范要求. CSS规范甚至没有触及它.

Section 10.4.2 of W3C HTML5描述了如何根据一组引用img元素所代表的规则来呈现img元素.

Section 4.7.1,向下,根据其src和altattributes描述img元素所代表的内容:

What an img element represents depends on the src attribute and the alt attribute.

[…]

If the src attribute is set and the alt attribute is set to a value that isn’t empty

The image is a key part of the content; the alt attribute gives a textual equivalent or replacement for the image.

If the image is available and the user agent is configured to display that image, then the element represents the element’s image data.

Otherwise, the element represents the text given by the alt attribute. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.

因此,如果图像不可用,则img元素表示其alt文本(因为没有要表示的图像!).

因此,回到10.4.2节,适用以下规则:

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.

似乎Firefox最接近这种期望(注意:不是要求),尽管生成的框是替换还是未替换,我不确定.对于其他浏览器也是如此 – 内联块可以替换也可以不替换.请注意,HTML表示“短语元素”,而不是“内联元素”或“内联块元素”,这再次增加了整个事物的模糊性.

当通过用户偏好禁用图像时Chrome所做的不是我所谓的“向用户提供图像存在但已从渲染中省略的通知”,但同样,这也不是必需的.不过,我不明白为什么Chrome认为这是一个好主意.什么是替代文字?