English 中文(简体)
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?
原标题:

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.

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 html>

is the way to 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.

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.

问题回答

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.

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

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.

Thanks guys for pointing me in the right direction.

First of all you probably want to avoid the Transitional Doctype for new content. 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.

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.

Personally I d go for either XHTML 1.0 Strict or 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.

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.

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.

The schemas for Visual Studio are usually kept in:

C:Program FilesMicrosoft Visual Studio 9.0Common7Packagesschemashtml

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

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:

<!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.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签