我今天应该定位什么 DOCTYPE?

发布于 2024-09-09 07:35:59 字数 431 浏览 5 评论 0原文

我正在重构一个 .Net Web 应用程序,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

现在的方法只是瞄准明星并选择最新的文档类型,只是因为它是最新的,我想做出更明智的选择并针对特定的文档类型并永远这样做原因。

存在类似的问题,但答案现在可能已经过时了。

标准和怪异模式之间的区别、优点和缺点是什么?使用不同设置的文档类型可能会遇到哪些怪癖?

有人告诉我,XHTML 文档类型比集成 AJAX 更好,因为 UpadtePanel 对其进行序列化,并且要做到这一点需要有 XHTML do 类型,这在多大程度上是正确的?

对于浏览器兼容性,浏览器在 DOCTYPE 方面正在朝哪个方向发展,是否存在共同趋势或有所不同?

I'm refactoring a .Net web application that is in

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

Right now the approach is just to aim for the stars and go for the latest doctype just because it's latest, I would like to make a wiser choice and target a specific one and for good reasons.

There are similar questions existing but the answers might be outdated now.

What is the difference, advantages, disadvantages between standards and quirks mode, what are some quirks I may run into with differently set doctypes?

I have been told that an XHTML doctype is preferable to integrate AJAX since the UpadtePanel serializes it and to do so needs to have a XHTML do type, to what extent is this true?

And for browser compatibility, in which direction are browsers going in terms of DOCTYPE, is there a common thrend or do they differ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无妨# 2024-09-16 07:35:59

HTML5 doctype(即

<!DOCTYPE html>

XHTML)作为标准基本上已失效,并且在大多数情况下从未得到正确实现。

HTML5 doctype, which is

<!DOCTYPE html>

XHTML is largely dead as a standard, and never was implemented correctly in most cases.

江湖正好 2024-09-16 07:35:59

任何 Doctype:

  • HTML 4.01 或 XHTML 1.0
  • Strict 或 Transitional

作为 html(不是 html+xml)应该没问题。没有更好的文档类型,您只需选择一个满足您需求的文档类型,然后遵守其规则即可。

  • 避免使用 Frameset,但如果必须的话,请使用 title 属性向屏幕阅读器用户描述每个框架的角色(顺便说一句,与 iframe 相同)。
  • Quirks 模式(无 Doctype)是 PITA,不惜一切代价避免它。 8年前这还可以。
  • 没有 XML 序言,除非您提供 html+xml(祝您好运!如果您喜欢不需要的复杂事物,那是您的选择)
  • 如果您被迫使用严格模式下禁止的属性(target=例如“_blank”)而不是使用过渡模式:这就是创建它的原因!请向您的用户表明该链接将在新页面中打开,无论是在链接文本中还是在其标题中。从可访问性的角度来看,这一点很重要。

HTML 5 是下一个大事件,我们正在等待它,但只要它不能在每个浏览器中工作(我的意思是没有 JS 的 IE),就不建议“认真”使用它公共网站。这还是草稿吗?如果几个月内全部重写怎么办?
我的网络代理机构在其网站上使用它,但我们不会很快在客户网站上使用它:现在还为时过早。

旁注:我经常看到诸如“HTML5 和 CSS3 中的现代网站”之类的流行语,暗示 CSS3 是为 HTML 5 制作的。CSS3 没有任何东西与 HTML5 相关,并且已经可以使用,只要它在旧浏览器上正常降级即可。
您可以使用 CSS2.1 或 HTML4.01 Transitional 设计 HTML5,并使用仅适用于 webkit nightly 的最新 CSS3 动画,没问题。

Any Doctype:

  • HTML 4.01 or XHTML 1.0
  • Strict or Transitional

served as html (not html+xml) should be OK. There's no such thing as a better doctype, you just have to choose one filling your needs and then stick to its rules.

  • Avoid Frameset, but if you've to, use the title attribute to describe the role of each frame to a screen reader user (same with iframe btw).
  • Quirks mode (no Doctype) is a PITA, avoid it at all cost. This was OK 8 years ago.
  • No XML prologue unless you're serving html+xml (good luck with that! If you like complicated things when it's not needed, that's your choice)
  • If you are forced to use attributes that are forbidden in Strict mode (target="_blank" for example) than use Transitional mode: this is why it was created! And please indicate to your users that the link will open in a new page, whether in the text of your link or in its title. This is important from an accessibility point of view.

HTML 5 is the next big thing, we're waiting for it but as long as it won't work in every browser (I mean IE without JS) it's not advisable to use it in "serious" public sites. Is it even a Draft? What if entire part of it are rewritten in a couple of months?
My web agency uses it for its website but we won't use it on a client site anytime soon: it's just too soon.

Sidenote: I often see catch phrases like "a modern website in HTML5 and CSS3" implying that CSS3 is made for HTML 5. CSS3 has nothing to do with HTML5 and can already be used, as long as it degrades gracefully on old browsers.
You can design HTML5 with CSS2.1 or HTML4.01 Transitional with the latest CSS3 animations that only work in webkit nightlies, no problem.

薄暮涼年 2024-09-16 07:35:59

新事物是 HTML 5。

是您用来指定它的内容。就是这样。没有 DTD 名称或 URL 或其他任何内容。

如果您使用类似 XML 的内容(例如 .net),那么您可能需要使用 XHTML。但不要出于任何其他原因这样做; XHTML 作为标准从未真正流行过,或者至少它几乎从未被正确使用过。

The new thing is HTML 5.

<!DOCTYPE html> is what you use to specify it. That's it. No DTD name or URL or whatever.

If you're using something that likes XML, like .net, then you might want to use XHTML. But don't do it for any other reason; XHTML never was really popular as a standard, or at least it was almost never used correctly.

看轻我的陪伴 2024-09-16 07:35:59

无论您选择什么,请确保您的 MIME 类型与您的 DOCTYPE 兼容

浏览器将使用 MIME 类型(HTTP 标头内容类型)来确定如何处理您的页面。例如:XHTML 1.1 Strict 的 DOCTYPE 作为 ContentType Text\HTML 被解析为 HTML。

DOCTYPE 很重要,但如果使用了错误的 ContentType,则基本上无关紧要。

Whatever you choose, make sure your MIME-Type is compatible with your DOCTYPE

The browser will use the MIME-Type (the HTTP Header ContentType) to determine how to treat your page. For example: A DOCTYPE of XHTML 1.1 Strict served as ContentType Text\HTML is parsed as HTML.

DOCTYPE is important, but largely irrelevant if the wrong ContentType is used.

苦笑流年记忆 2024-09-16 07:35:59

浏览器从未真正使用 DOCTYPE 来确定文档的标记语言(它们使用 HTTP Content-type 代替),因此您选择的 DOCTYPE 从来没有太大的相关性 - 只要您使用某种描述的有效 DOCTYPE 。无论您选择哪一个都取决于您。

如果您正在编写 HTML, 是最短的输入方式,并将所有浏览器置于标准模式(这正是您想要的)。

如果您正在编写 XHTML, 也是完全合法的(XHTML 实际上根本不需要 DOCTYPE,因为它完全依赖于 HTTP Content-type,但是放置 DOCTYPE 也没有什么坏处)为了可移植性,

不要使用 - 虽然这在技术上是有效的 HTML,但它是无效的 XHTML,因此如果您尝试将页面解析为 XML,则会稍稍出错


。 OT 旁注:这里有些人评论说 XHTML 是一个“死”标准 - 这是错误的 XHTML 已集成到即将推出的 HTML5 规范中。该规范的标题是“HTML5:HTML 的词汇表和相关 API”。 XHTML"

请参阅:

Browsers have never actually used DOCTYPE to determine the markup language of your document (they use HTTP Content-type instead), so which DOCTYPE you chose was never hugely relevant - just as long as you are using a valid DOCTYPE of some description. Whichever you choose is up to you.

If you're writing HTML, <!DOCTYPE html> is the shortest to type, and puts all browsers into standards mode (which is what you want).

If you're writing XHTML, <!DOCTYPE html> is also perfectly legitimate (XHTML actually requires no DOCTYPE at all, as it relies entirely on HTTP Content-type, but there's no harm putting a DOCTYPE in for portability.

Don't use <!doctype html> - while this is technically valid HTML, it's invalid XHTML so will break if you ever try to parse your page as XML.


Slightly OT sidenote: Some people here have commented that XHTML is a "dead" standard - this is false. XHTML has been integrated into the upcoming HTML5 spec. The spec is entitled "HTML5: A vocabulary and associated APIs for HTML and XHTML"

See:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文