HTML 中的 <img> 与 <image> 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11928566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<img> vs <image> tag in HTML
提问by Mike
I am writing an introductory HTML course. I remember discovering 9 years ago as I was learning HTML that both <img>
and <image>
worked as the tag for displaying images, at least in IE. Indeed, <image>
still works in the latest versions of the 5 top browsers.
我正在编写一个介绍性的 HTML 课程。我记得发现9年前,因为我是学习HTML,这两个<img>
并<image>
担任该标签用于显示图像,至少在IE浏览器。事实上,<image>
仍然适用于 5 个顶级浏览器的最新版本。
I realize that <image>
is incorrect and will not validate with http://validator.w3.org. However, is anyone aware of a browser that will not display an image if <image>
is used instead of <img>
?
我意识到这<image>
是不正确的,并且不会使用http://validator.w3.org 进行验证。但是,有人知道如果<image>
使用 代替 ,浏览器将不显示图像<img>
吗?
Furthermore, I assume the modern browsers display images created with the <image>
tag simply because it is a common mistake that beginners make. Is this assumption correct?
此外,我认为现代浏览器显示使用<image>
标签创建的图像仅仅是因为这是初学者常犯的错误。这个假设正确吗?
采纳答案by Alohci
Yes and no. As you point out <image>
has been a synonym for <img>
for a long time. I believe it was an early Netscape browser that first did this, possibly to compensate for user error, or possibly because there was dispute at the time whether the element should actually be called <image>
or <img>
.
是和否。正如您所指出的,<image>
长期以来一直是同义词<img>
。我相信这是早期的 Netscape 浏览器首先这样做的,可能是为了弥补用户错误,或者可能是因为当时对该元素是否应该实际调用<image>
或<img>
.
Anyway, as pst points out, once it was implemented in a browser that dominated the market of the time, web pages came to rely on it. Its persistence is then down to commercial pressure on the browser manufacturers. If all the major browsers support it, then Browser A decides that although it supported it in Version V, it won't support it in version V+1, as soon as version V+1 is released, they get lots of messages saying "Site S is broken in your latest browser. You browser is rubbish. I'm going to switch to browser B".
无论如何,正如 pst 指出的那样,一旦它在当时主导市场的浏览器中实现,网页就开始依赖它。它的持久性取决于浏览器制造商的商业压力。如果所有主流浏览器都支持,那么浏览器A决定虽然V版本支持,但V+1版本不支持,V+1版本一发布,他们就会收到很多消息说“站点 S 在您最新的浏览器中坏了。您的浏览器是垃圾。我要切换到浏览器 B”。
The HTML5 parsing spec requires that the <image>
tag is mapped to the img
element at the tree construction stage, so there can never be any justification for using it.
HTML5 解析规范要求<image>
标签img
在树构建阶段映射到元素,因此永远没有任何理由使用它。
I would be less concerned about browsers, than other HTML consumers, such as the lesser known search engines. I believe that the image
for img
synonym is not widely known, and the many such tools would therefore fail to pick up <image>
as referencing an image resource.
与其他 HTML 消费者(例如鲜为人知的搜索引擎)相比,我不太关心浏览器。我相信image
forimg
同义词并不广为人知,因此许多此类工具将无法<image>
引用图像资源。
回答by jgrumps
回答by user3642643
I just finished debugging this problem, which I was committing, having not previously read the above answers.
我刚刚完成调试这个我正在提交的问题,之前没有阅读上述答案。
While not full-blown browsers, an email client is often used as if it were a browser.
虽然不是成熟的浏览器,但电子邮件客户端通常用作浏览器。
I discovered, the hard way, that the Android Gmail client, using naked HTML (with a default naked DTD specification), does exhibit this problem. It only responds to <img />
[i.e., not <image />
]. gmail.com is fine with <image />
, but not the Android gmail client.
我艰难地发现,使用裸 HTML(具有默认裸 DTD 规范)的 Android Gmail 客户端确实存在此问题。它只响应<img />
[ie, not <image />
]。gmail.com 适用于<image />
,但不适用于 Android gmail 客户端。
While an email client isn't really a browser, I thought you might be interested anyway.
虽然电子邮件客户端并不是真正的浏览器,但我认为您可能会感兴趣。
回答by Andreas Christodoulou
Indeed. Modern browsers will display code that is not valid in order to make sure that old websites still display correctly and slightly-invalid code doesn't screw up a page.
的确。现代浏览器会显示无效的代码,以确保旧网站仍能正确显示,并且稍微无效的代码不会搞砸页面。
For example, forgetting to close a <tr>
before you open a new one - all modern browsers will simply assume you closed it.
例如,<tr>
在打开一个新的之前忘记关闭一个 - 所有现代浏览器都会假设你已经关闭了它。
I'm not aware of a well-used, up-to-date browser that will fail to display an <image>
tag, but will display an <img>
tag.
我不知道使用良好的最新浏览器将无法显示<image>
标签,但会显示<img>
标签。