HTML 5 与 XHTML 1.0 过渡?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/256953/
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
HTML 5 versus XHTML 1.0 Transitional?
提问by Brennan
It seems that HTML 5 is going to be supported (partially) by Firefox 3.1 and other browsers. It is adding support for video and audio as tags, but these are new tags that XHTML 1.0 Transitional does not recognize. What is the behavior supposed to be if I use a new HTML 5 tag in a future version of Firefox but use the DTD for XHTML? And what if I mix HTML 5 markup with XHTML 1.0 Trans?
Firefox 3.1 和其他浏览器似乎将(部分)支持 HTML 5。它增加了对视频和音频作为标签的支持,但这些是 XHTML 1.0 Transitional 无法识别的新标签。如果我在未来版本的 Firefox 中使用新的 HTML 5 标签,但对 XHTML 使用 DTD,应该会出现什么行为?如果我将 HTML 5 标记与 XHTML 1.0 Trans 混合会怎样?
This is getting confusing. Why didn't they just add these tags to XHTML? How do we support both XHTML and HTML 5?
这越来越令人困惑。他们为什么不直接将这些标签添加到 XHTML 中?我们如何同时支持 XHTML 和 HTML 5?
Video on HTML 5: http://www.youtube.com/watch?v=xIxDJof7xxQ
HTML 5 视频:http: //www.youtube.com/watch?v=xIxDJof7xxQ
采纳答案by hangy
Well, generally speaking HTML is SGML and XHTML is expressed in XML. Because of that, creating XHTML is connected with more restrictions (in the form of markup) than HTML is. (SGML-based versus XML-based HTML)
嗯,一般来说 HTML 是 SGML,XHTML 是用 XML 表示的。因此,与 HTML 相比,创建 XHTML 会受到更多限制(以标记的形式)。(基于 SGML 与基于 XML 的 HTML)
As mentioned on Wikipedia, HTML 5 will also have a XHTML variant (XHTML 5).
正如在Wikipedia 上提到的,HTML 5 也将有一个 XHTML 变体 (XHTML 5)。
Rule of thumb: You should always use valid markup. That also means that you should not use the mentioned <video>or <audio>tags in XHTML 1.0 Transitional, as those are not an element of that specification. If you really needto use those tags (which I highly doubt), then you should make sure that you use the HTML 5/XHTML 5 DTD in order to specify that your document is in that DOCTYPE.
经验法则:您应该始终使用有效的标记。这也意味着您不应使用XHTML 1.0 Transitional 中提到的<video>或<audio>标签,因为它们不是该规范的元素。如果您真的需要使用这些标签(我非常怀疑),那么您应该确保使用 HTML 5/XHTML 5 DTD 以指定您的文档在该 DOCTYPE 中。
Using HTML 5 or XHTML 5 in the given state of the implementation (AFAIK, the standard is not even settled, yet, correct?) could be counter-productive, as almost all users may not see the website rendered correclty anyways.
在给定的实现状态下使用 HTML 5 或 XHTML 5(AFAIK,标准甚至还没有确定,但是,对吗?)可能会适得其反,因为几乎所有用户都可能看不到网站呈现的正确性。
Edit 2013: Because of the recent downvotes and since this accepted answer cannot be deleted (by me), I would like to add that the support and standardization process of HTML5 is nowadays totally different to what it was when I wrote this answer five years ago. Since most major browsers support most parts of the HTML5 draft and because a lot of stuff can be fixed with polyfills in older browsers, I mainly use HTML5 now.
2013 年编辑:由于最近的反对票以及此已接受的答案无法删除(由我),我想补充一点,现在 HTML5 的支持和标准化过程与我五年前编写此答案时的完全不同. 由于大多数主流浏览器都支持 HTML5 草案的大部分内容,并且因为在旧浏览器中可以使用 polyfills 修复很多东西,所以我现在主要使用 HTML5。
回答by Shadow2531
HTML5 is so much easier to write than XHTML 1.0.
HTML5 比 XHTML 1.0 更容易编写。
You don't have to manually declare the "http://www.w3.org/1999/xhtml" namespace.
You don't have to add type attributes to script and style elements (they default to text/javascript and text/css).
You don't have to use a long doctype where the browser just ignores most of it. You must use <!DOCTYPE html>, which is easy to remember.
You don't have a choice to include or not include a dtd uri in the doctype and you don't have a choice between transitional and strict. You just have a strict doctype that invokes full standards mode. That way, you don't have to worry about accidentally being in Almost standards mode or Quirks mode.
The charset declaration is much simpler. It's just <meta charset="utf-8">.
If you find it confusing to write void elements as <name>, you can use <name/>, if you want.
HTML5 has a really good validator at http://validator.nu/. The validator isn't bound by a crappy DTD that can't express all the rules.
You don't have to add //<
