加载图像时出现 Firefox 替代文本

Fre*_*d K 6 html css firefox image alt

Firefox上,如果刷新页面,您将看到加载图像时出现的替代文本。

您可以在Mozilla 页面上看到它(检查第一张图片)。

Chrome 和其他现代浏览器上不会发生这种情况。

我在 Bugzilla 上发现了一个老问题,但结果是“已修复”。

关于这个主题,我找到了这个伪解决方案(也在Stack上)

img:-moz-loading {
  visibility: hidden;
}
Run Code Online (Sandbox Code Playgroud)

效果很好,但正如文档所说,它是非标准的

非标准 此功能是非标准的,并且不在标准轨道上。不要在面向 Web 的生产站点上使用它:它不适用于每个用户。实现之间也可能存在很大的不兼容性,并且行为将来可能会发生变化。

有什么解决办法吗?

注意:我不会考虑类似color: transparent或类似的解决方案,根据需要向用户隐藏替代文本。

小智 4

您可以在需要时使用onloadonerror重置替代文本的颜色:

<img style="color: transparent;" onload="this.style.color='black'" onerror="this.style.color='black'" src="https://source.unsplash.com/random/100x100" alt="Alternate text" />
Run Code Online (Sandbox Code Playgroud)