我的 IE7/IE8/FF3+ 的 HTML 输出推荐使用什么 DOCTYPE?以及如何在 Visual Studio 中更新我的 HTML 验证以反映该更改?

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

What DOCTYPE is recommended for my HTML output for IE7/IE8/FF3+? and how can I update my HTML validation in Visual Studio to reflect that change?

htmlvisual-studio-2008xhtmldoctype

提问by Ben Lesh

I noticed that Visual Studio defaults the DOCTYPE to XHTML 1.0 Transitional. This seems okay, but I think that's more of a standard for "generation 6" browsers. We're now in gen 7 and 8 browsers, and I'm wondering what DOCTYPE I should be putting in my HTML.

我注意到 Visual Studio 将 DOCTYPE 默认为 XHTML 1.0 Transitional。这似乎没问题,但我认为这更像是“第 6 代”浏览器的标准。我们现在在第 7 代和第 8 代浏览器中,我想知道应该在我的 HTML 中放入什么 DOCTYPE。

On a related note: Is there a way to add other DOCTYPEs to the HTML validation in Visual Studio 2008? Tools > Options > Text Editor > HTML > Validation

相关说明:是否可以将其他 DOCTYPE 添加到 Visual Studio 2008 中的 HTML 验证中?工具 > 选项 > 文本编辑器 > HTML > 验证

回答by BalusC

<!doctype html>

is the wayto go. This works fine in all decent browsers, including IE6 (not that it is a decent one though). Also see http://hsivonen.iki.fi/doctype/for more background info and a browser behaviour table.

是要走的。这在所有像样的浏览器中都可以正常工作,包括 IE6(虽然它不是一个像样的浏览器)。另请参阅http://hsivonen.iki.fi/doctype/了解更多背景信息和浏览器行为表。

You could also consider XHTML strict, but why would you massage clean HTML into a XML format? It is only interesting if you want to parse/generate/validate HTML using some XML tool, which often isn't the case in real world. Google also just uses <!doctype html>and Stackoverflow uses nicely HTML strict.

您也可以考虑严格的 XHTML,但是为什么要将干净的 HTML 转换为 XML 格式呢?只有当您想使用一些 XML 工具解析/生成/验证 HTML 时才有趣,这在现实世界中通常不是这种情况。谷歌也只是使用<!doctype html>和 Stackoverflow 很好地使用 HTML 严格。

回答by Ben Lesh

Note to anyone else reading this thread looking for answers: I've just discovered that the declaration for HTML 5 is simply <!DOCTYPE HTML>nothing fancy there, really.

请注意阅读此线程以寻找答案的其他人:我刚刚发现 HTML 5 的声明在<!DOCTYPE HTML>那里根本没有什么特别之处,真的。

Also, to add HTML5 validation to Visual Studio 2008 I found this article. It's working pretty well so far.

此外,为了向 Visual Studio 2008 添加 HTML5 验证,我发现了这篇文章。到目前为止,它运行良好。

Other things to note: Visual Studio adds xmlns="http://www.w3.org/1999/xhtml"to your <html>tag, and you probably don't want/need that in there if you're going for HTML5.

其他需要注意的事项:Visual Studio 添加xmlns="http://www.w3.org/1999/xhtml"到您的<html>标签中,如果您要使用 HTML5,您可能不希望/不需要它。

Thanks guys for pointing me in the right direction.

谢谢你们为我指出正确的方向。

回答by Jamie Dixon

Personally I'd go for either XHTML 1.0 Strict or HTML 4.01 Strict.

我个人会选择 XHTML 1.0 Strict 或 HTML 4.01 Strict。

Unless you're literally "transitioning" from using older versions of HTML, it doesn't make much sense to use the transitional doctype.

除非您实际上是从使用旧版本的 HTML 中“过渡”,否则使用过渡文档类型没有多大意义。

XHTML 1.1 is also an option however you'll need to ensure you're serving your document with a application/xhtml+xml MIME type.

XHTML 1.1 也是一个选项,但是您需要确保使用 application/xhtml+xml MIME 类型提供文档。

HTML 5 is still very new but could be an option if you're putting out something cutting edge that you only expect to work in the most up-to-date browsers.

HTML 5 仍然很新,但如果您要推出只希望在最新浏览器中使用的尖端技术,那么它可能是一个选择。

The schemas for Visual Studio are usually kept in:

Visual Studio 的架构通常保存在:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html

C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html

I beleive you can add new ones in here as needed. I'll post more details on this as I find it.

我相信您可以根据需要在此处添加新的。当我找到它时,我会发布更多细节。

回答by Joey

First of all you probably want to avoid the TransitionalDoctype for newcontent. Transitional is intended for legacy content that needs to be thoroughly altered before confirming to the strict DTDs but this isn't an issue for new documents.

首先,您可能希望避免内容的TransitionalDoctype 。Transitional 用于在确认严格的 DTD 之前需要彻底更改的遗留内容,但这对于新文档来说不是问题。

Furthermore, at least in my experience XHTML generates more trouble than it's beneficial. Unless you require XHTML for some things (such as allowing XML parsers to read your site [but even then chances are that it doesn't validate and therefore is unsuitable for that]) I'd recommend sticking to HTML 4 Strict. Also XHTML needs special attention with IE, even in IE 8.

此外,至少在我的经验中,XHTML 产生的麻烦多于它的好处。除非您需要 XHTML 来处理某些事情(例如允许 XML 解析器读取您的网站 [但即便如此,它也有可能无法验证,因此不适合该用途]),否则我建议您坚持使用 HTML 4 Strict。即使在 IE 8 中,XHTML 也需要特别注意 IE。

回答by Scott

You should be using a Strict doctype. Whether that's HTML 4.01 Strict or XHTML 1.0 Strict is up to you. Lately I've personally been using the following:

您应该使用严格的文档类型。是 HTML 4.01 Strict 还是 XHTML 1.0 Strict 取决于您。最近我个人一直在使用以下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

I really like the way RDFa works. It bolts onto HTML more cleanly than microformats by defining its own attributes rather than overloading the class and title attributes. But because RDFa is still not really consumable like microformats are, I'm using both alongside each other.

我真的很喜欢 RDFa 的工作方式。通过定义自己的属性而不是重载类和标题属性,它比微格式更清晰地固定在 HTML 上。但是因为 RDFa 仍然不像微格式那样真正可以使用,所以我将两者一起使用。