有什么理由不开始使用 HTML 5 doctype?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5629/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:07:19  来源:igfitidea点击:

Any reason not to start using the HTML 5 doctype?

htmldoctype

提问by Ricky

It is supposed to be backwards compatible with HTML4 and XHTML. John Resig posted about some of the benefits.

它应该向后兼容 HTML4 和 XHTML。John Resig 发布了一些好处

As long as we don't use any of the new and not supported yet features, would there be any downside to start building sites with this doctype?

只要我们不使用任何新的和尚不支持的功能,使用这种文档类型开始构建网站会有什么缺点吗?

回答by Shadow2531

Well consider this:

那么考虑一下:

When serving as text/html, all you need a doctype for is to trigger standards mode. Beyond that, the doctype does nothing as far as browsers are concerned.

当用作 text/html 时,您只需要一个 doctype 就可以触发标准模式。除此之外,就浏览器而言,文档类型没有任何作用。

When serving as text/html, whether you use XHTML markup or HTML markup, it's treated by browsers as HTML.

当作为 text/html 使用时,无论您使用 XHTML 标记还是 HTML 标记,浏览器都将其视为 HTML。

So, really it comes down to using the shortest doctype that triggers standards mode (<!DOCTYPE html>) and using HTML markup that produces the correct result in browsers.

因此,实际上归结为使用触发标准模式的最短文档类型 (<!DOCTYPE html>) 并使用在浏览器中产生正确结果的 HTML 标记。

The rest is about conforming, validation and markup prerference.

其余的是关于一致性、验证和标记偏好。

With that said, using <!DOCTYPE html> now and trying to make your markup conform to HTML5 is not a bad idea as long as you stick to stable features that work in browsers now. You wouldn't use anything in HTML4 or XHTML 1.x that doesn't work in browsers, would you?

话虽如此,现在使用 <!DOCTYPE html> 并尝试使您的标记符合 HTML5 并不是一个坏主意,只要您坚持现在可以在浏览器中使用的稳定功能。您不会在 HTML4 或 XHTML 1.x 中使用在浏览器中不起作用的任何内容,对吗?

In other words, you use <!DOCTYPE html> with HTML4-like markup while honoring things that have been clarified in HTML5. HTML5 is about browser compatibility after all.

换句话说,您将 <!DOCTYPE html> 与 HTML4 类似的标记一起使用,同时尊重 HTML5 中已阐明的内容。毕竟 HTML5 是关于浏览器兼容性的。

The downside to using HTML5 now is that the spec can change quite often. This makes it important for you to keep up with the spec as it actively changes. Also http://validator.nu/might not always be up-to-date, but http://validator.w3.org/isn't always up-to-date either, so don't let that stop you.

现在使用 HTML5 的缺点是规范可能会经常更改。这使您在规范积极变化时跟上规范很重要。此外,http://validator.nu/可能并不总是最新的,但http://validator.w3.org/也不总是最新的,所以不要让这阻止你。

Of course, if you want to use XHTML 1.0 markup and conform to XHTML 1.0, then you shouldn't use <!DOCTYPE html>.

当然,如果您想使用 XHTML 1.0 标记并符合 XHTML 1.0,那么您不应该使用 <!DOCTYPE html>。

Personally, I always use <!DOCTYPE html> for HTML.

就个人而言,我总是将 <!DOCTYPE html> 用于 HTML。

回答by Justin Yost

My question to you would be why use it if you don't use any of the new/unsupported features. I'm not saying you couldn't play around with it, but why start building sites with a doctype that offers no benefits and could be supplemented by XHTML5.

我的问题是,如果您不使用任何新的/不受支持的功能,为什么要使用它。我并不是说你不能玩它,但为什么开始使用没有任何好处并且可以由 XHTML5 补充的文档类型来构建站点。

回答by Bernard

I'd say use it and test extensively. Then let us know if it blew your house up or something. :')

我会说使用它并进行广泛的测试。然后让我们知道它是否炸毁了你的房子或其他什么。:')

回答by hsivonen

Based on the latest IE8 beta, it seems that MS will use the HTML5 doctype as a bypass for the IE8 mode switching quagmire. It seems that the biggest risk with deploying the HTML5 doctype early is that if people publish a lot of IE8-incompatible content with the HTML5 doctype before IE8 ships, MS might get cold feet about making the mode situation simple for HTML5.

基于最新的 IE8 测试版,似乎 MS 将使用 HTML5 doctype 作为绕过 IE8 模式切换的泥潭。早期部署 HTML5 doctype 的最大风险似乎是,如果人们在 IE8 发布之前发布了大量与 IE8 不兼容的 HTML5 doctype 内容,MS 可能会对让 HTML5 的模式情况变得简单感到冷淡。

Update:This has been voted down, it seems. Quite obviously now that IE8 has shipped, the above consideration no longer applies. And indeed, the situation is not simple with IE8.

更新:这似乎已被否决。很明显,现在 IE8 已经发布,上述考虑不再适用。事实上,IE8 的情况并不简单

回答by Mediascreen

The downside for me mainly concerns validation:

我的缺点主要是验证:

  1. Third party validation tools does not always keep up with changing specs, making my favorite tools unreliable.
  2. I prefer to validate against strict doctypes to make sure I have closed all elements. It's an easy way to avoid simple but time consuming nesting errors. With HTML 5 you don't have to close your elements, so there is no way to find unmatched tags.
  1. 第三方验证工具并不总是跟上不断变化的规范,这让我最喜欢的工具变得不可靠。
  2. 我更喜欢针对严格的文档类型进行验证,以确保我已关闭所有元素。这是避免简单但耗时的嵌套错误的简单方法。使用 HTML 5,您不必关闭元素,因此无法找到不匹配的标签。

回答by Mediascreen

Consider your audience and your needs. I write pages such as class testswith a target audience of students in my courses who use FireFox 3 in an Ubuntu equipped computer laboratory. I need SVG with MathMl embedded as a foreignObject in the SVG. I use the HTML5 doctype and new HTML5 tags freely.

考虑您的受众和您的需求。我编写了一些页面,例如课堂测试,目标受众是我课程中在配备 Ubuntu 的计算机实验室中使用 FireFox 3 的学生。我需要将 MathMl 作为外来对象嵌入到 SVG 中的 SVG。我自由地使用 HTML5 文档类型和新的 HTML5 标签。

回答by helloandre

if you're going to use the doctype, experiment with the features. As long as they don't go into a production site, and you test them thoroughly, have at it.

如果您打算使用 doctype,请尝试使用这些功能。只要它们不进入生产现场,并且您对它们进行了彻底的测试,就可以使用它。

回答by helloandre

Take a look at this blog post! Not really a fan of HTML5 http://www.webscienceman.com/2009/01/24/html-xhtml-html5-future-html/

看看这篇博文!不是真正的 HTML5 粉丝 http://www.webscienceman.com/2009/01/24/html-xhtml-html5-future-html/

回答by Faraz Kelhini

For anyone finding this. The chart at http://hsivonen.iki.fi/doctype/shows the various rendering modes different browsers use depending on the DOCTYPE declaration in use. It give you a good idea of how DOCTYPE switching works.

对于任何发现这个的人。图表 http://hsivonen.iki.fi/doctype/显示了不同浏览器使用的各种渲染模式,具体取决于使用的 DOCTYPE 声明。它让您对 DOCTYPE 切换的工作原理有一个很好的了解。

回答by graham.reeds

Personally I'd say no. There is no clear benefit to HTML5 and in fact would go as far as to say that the whole thing is botched from the start.

我个人会说不。HTML5 没有明显的好处,实际上甚至可以说整个事情从一开始就搞砸了。

Having specialised tags for header, footers and sidebars is a huge mistake - you've got them already in the form of tags (div) and names (classes/id's). Why do we need the specialist ones? XHTML1.1 is good enough, period. In fact, since most browsers don't support HTML4 correctly, there is little point in using a doctype that is going to take years to get proper support.

为页眉、页脚和侧边栏设置专门的标签是一个巨大的错误——你已经以标签(div)和名称(类/id)的形式获得了它们。为什么我们需要专家?XHTML1.1 已经足够好了。事实上,由于大多数浏览器不正确支持 HTML4,因此使用需要数年时间才能获得适当支持的文档类型毫无意义。