现代浏览器是否关心DOCTYPE? [英] Do modern browsers care about the DOCTYPE?

查看:80
本文介绍了现代浏览器是否关心DOCTYPE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用已弃用的属性或标记< center> < font color =red> < td valign =top> 等等,在XHTML 1.0 Strict(没有depr。属性),现代浏览器(我会用Chrome作为例子)如果您在XHTML 1.0 Strict DOCTYPE上使用HTML5 < video> ,那么请注意并使用它们。

Chrome浏览器仍然会认出它 - 它并不像编程它不。我测试了最差的弃用的,大写和未加引号的属性代码,以及HTML5音频,以及Chrome中的XHTML 1.0 Strict DOCTYPE,并且它完美无瑕地呈现。



这是我测试过的代码,在Chrome中完美运行(红色bg,居中表,音频播放):

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 // EN
http://www.w3.org/TR/html4/strict.dtd\">
< html>
< head>
< title>浏览器是否关心DOCTYPE?< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< / head>
< body bgcolor =#ff0000>
< CENTER>
< table cellpadding =0cellspacing = 0>
< tr>< td valign = top>测试< / td>< / tr>
< / table>
< / CENTER>
和一些HTML5音频..
<音频自动播放>
< source src =http://www.duncannz.com/resources/sound/alarm.mp3type =audio / mp3>后备文本< / audio>
< / body>
< / html>



所以我的问题:现代浏览器(翻译:IE以外的浏览器)由于DOCTYPE的原因,请不要使用任何关注,或者做任何不同的事情。他们甚至懒得阅读和解释它吗?

解决方案

浏览器确实关心DOCTYPE - 否则不会有任何问题拥有它!

你说得对,许多浏览器以正确的方式解释旧的/弃用的命令,但这主要是向后兼容的问题。网络上有这么大量的内容,几乎不可能让所有内容保持最新和标准兼容。网页浏览器继续支持这些过时的页面,因为如果他们不这样做,网页上的大部分内容都会略显偏离。大多数用户不知道HTML4和5之间的区别,所以责备可能会落在浏览器上,这可能是毁灭性的 - 尤其是如果一个页面在Firefox上看起来很糟糕,而且在IE上很好!



DOCTYPE主要用于验证并确定浏览器是否运行在这种怪癖模式(许多这些较旧的规则仍然有效)或标准模式下。许多专业网页设计人员使用W3C验证工具来确保他们的网页是有效的HTML,并且他们网站提供的工具查看DOCTYPE以选择要验证的正确规则集。此外,XHTML strict不允许出现空标签或其他明显的语法错误。



希望这有助于您!


If you use deprecated attributes or tags <center>, <font color="red">, or <td valign="top"> etc. in XHTML 1.0 Strict (no depr. attributes), modern browsers (I will use Chrome as an example) still take notice of and use them.

If you use HTML5 <video> on an XHTML 1.0 Strict DOCTYPE Chrome will still recognize it - it's not as if they'd program it to not. I tested the worst deprecated, capitalized, and unquoted attribute code I could write, along with HTML5 audio, with the XHTML 1.0 Strict DOCTYPE in Chrome and it rendered flawlessly.

Here's the code I tested, working flawlessly in Chrome (red bg, centered table, audio playing):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Do browsers care about the DOCTYPE?</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body bgcolor=#ff0000>
 <CENTER>
  <table cellpadding="0" cellspacing=0>
   <tr><td valign=top>test</td></tr>
  </table>
 </CENTER>
 and some HTML5 audio..
 <audio autoplay>
  <source src="http://www.duncannz.com/resources/sound/alarm.mp3" type="audio/mp3">fallback text</audio>
</body>
</html>


So my question: Do modern browsers (translation: browsers other than IE) pay any attention at all, or do anything differently, because of the DOCTYPE? Do they even bother to read and interpret it?

解决方案

Browsers do care about the DOCTYPE - otherwise there wouldn't be any point in having it!

You are right in saying that many browsers interpret old/deprecated commands in the correct way, but this is largely a matter of backwards compatibility. There is such a huge amount of content on the web that it is next to impossible to keep everything up-to-date and standards-complient. The web browsers continue to support these outdated pages because if they didn't, much of the content on the web would look slightly off. Most users don't know the difference between HTML4 and 5, so the blame could fall on the browser, which could be devastating - especially if a page looks bad on Firefox and nice on IE!

The DOCTYPE is mainly used in validation and to determine whether a browser runs in this "quirks mode" (where many of these older rules still work) or "standards mode" . Many professional web designers use the W3C validation tools to make sure their web pages are valid HTML, and the tools provided by their website look at the DOCTYPE to choose the correct set of rules with which to validate. Furthermore, XHTML strict does not allow empty tags or other blatant syntactic errors.

Hope this helps!

这篇关于现代浏览器是否关心DOCTYPE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆