简体   繁体   English

是否可以将HTML5元素与旧HTML4一起使用?

[英]Is it possible to use HTML5 elements with old HTML4?

I've used the video element in my web page but the DOCTYPE is HTML4. 我在网页中使用了video元素,但DOCTYPE是HTML4。

Then, I can use frameset in HTML5 also. 然后,我也可以在HTML5中使用frameset

Why there is no restriction on tag usage? 为什么对标签的使用没有限制?

HTML is designed to be tolerant of errors. HTML旨在容忍错误。 Using a particular doctype won't make browsers reject tags that weren't around when that doctype was published. 使用特定的doctype不会使浏览器拒绝发布该doctype时不在的标记。

This is why the current HTML doctype is just <!DOCTYPE html> , ie unversioned. 这就是当前HTML doctype只是<!DOCTYPE html> ,即无版本。 It more accurately reflects HTML as an ever-evolving standard. 它更准确地反映了HTML作为一种不断发展的标准。

Why there is no restriction on tag usage? 为什么对标签的使用没有限制?

Why should browsers ensure that? 为什么浏览器应该确保? If all browsers would only display valid HTML, great! 如果所有浏览器仅显示有效的HTML,那就太好了! But then one browser comes and says: "Oh, my users can't view all this invalid sites, but some of them would be really useful … let me show them those sites anyway!" 但随后一个浏览器出现并说:“哦,我的用户无法查看所有这些无效网站,但其中一些非常有用......无论如何,让我向他们展示这些网站!” Now this browser works with more sites than any other browser. 现在,此浏览器可用于比其他浏览器更多的站点。 You can bet what the other browsers will do. 您可以打赌其他浏览器会做什么。

Also, user agents that support HTML5 can't really tell if a page is in HTML 4.01 or HTML5, as the HTML 4.01 DOCTYPE is a " obsolete permitted DOCTYPE string " in HTML5. 此外,支持HTML5的用户代理无法确定页面是否在HTML 4.01或HTML5中,因为HTML 4.01 DOCTYPE是HTML5中的“ 过时允许的DOCTYPE字符串 ”。 Which means: Even if you use the HTML 4.01 DOCTYPE, those browsers will probably interpret your page according to HTML5. 这意味着:即使您使用HTML 4.01 DOCTYPE,这些浏览器也可能会根据HTML5解释您的页面。

Why HTML4 elements that are "obsolete" in HTML5 work in HTML5 documents? 为什么HTML5中“过时”的HTML4元素在HTML5文档中起作用? Because HTML5 user agents must support them (but authors must not use them!): see Frames in the HTML5 spec, which defines what user agents shall do with frameset . 因为HTML5用户代理必须支持它们(但作者不能使用它们!):请参阅HTML5规范中的框架 ,该框架定义了用户代理应对frameset做什么。

The doctype declaration is, of old, merely a hint to the browser on how to parse the content of the page. doctype声明是旧的,仅仅是浏览器关于如何解析页面内容的提示。 As of HTML5, this was dropped and replaced with a simple generic <!doctype html> that is identical for all current and future versions of the standards since HTML is now sufficiently backwards compatible to allow progressive development. 从HTML5开始,这被删除并替换为简单的通用<!doctype html> ,它对于所有当前和未来版本的标准都是相同的,因为HTML现在足够向后兼容以允许渐进式开发。

Long story short, all a modern browser does with the doctype nowadays is decide whether to parse in 'tag soup' or 'quirks' mode, or 'standards compliant mode'. 简而言之,所有现代浏览器都使用doctype来决定是在“标签汤”还是“怪癖”模式或“标准兼容模式”中进行解析。 The supported elements it then finds with that parser have nothing to do with the doctype. 然后,使用该解析器找到的受支持元素与doctype无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM