什么是文档类型

Any HTML document must start with a Document Type Declaration (abbreviated doctype) in the first line, which tells the browser the version of HTML used in the page.

任何HTML文档都必须在第一行中以“文档类型声明” (缩写为doctype ) 开头 ,该声明告诉浏览器页面中使用HTML版本。

This doctype declaration (case insensitive):

此doctype声明(不区分大小写):

<!DOCTYPE html>

tells the browser this is an HTML5 document.

告诉浏览器这是一个HTML5文档

浏览器渲染模式 (Browser rendering mode)

With this declaration, the browser can render the document in standards mode.

使用此声明,浏览器可以在标准模式下呈现文档。

Without it, browsers render the page in quirks mode.

没有它,浏览器将以怪癖模式呈现页面。

If you’ve never heard of quirks mode, you must know that browsers introduced this rendering mode to make pages written in an “old style” compatible with new functionality and standards used. Without it, as browsers and HTML evolved, old pages would break their appearance, and the Web Platform has historically been very protective in this regard (which I think is part of its success).

如果您从未听说过怪癖模式,则必须知道浏览器引入了此渲染模式,以使以“旧样式”编写的页面与所使用的新功能和标准兼容。 没有它,随着浏览器和HTML的发展,旧页面将无法显示它们的外观,并且Web平台在这方面一直具有很好的保护作用(我认为这是其成功的一部分)。

Browsers basically default to quirks mode unless they recognize the page is written for standards mode.

除非浏览器识别页面是为标准模式编写的,否则它们基本上默认为怪癖模式。

You want standards mode, and

您需要标准模式 ,并且

<!DOCTYPE html>

is the way to get it.

是获得它的方法。

There’s an additional care to be put for Internet Explorer <= 10 users to avoid quirks mode, and it’s to put

对于Internet Explorer <= 10的用户,还需要格外小心,以避免出现怪癖模式,

<meta http-equiv="X-UA-Compatible" content="IE=Edge">

in the page <head> tag, before loading any script.

在加载任何脚本之前,在<head>标签页中。

较旧HTML版本 (Older HTML versions)

HTML has a weird set of versions:

HTML有一组奇怪的版本:

  • HTML (1991)

    HTML(1991)
  • HTML 2.0 (1995)

    HTML 2.0(1995)
  • HTML 3.2 (1997)

    HTML 3.2(1997)
  • HTML 4.01 (1999)

    HTML 4.01(1999)
  • XHTML (2000)

    XHTML(2000)
  • HTML5 (2014)

    HTML5(2014)

The doctype of an HTML 4.01 Strict document was:

HTML 4.01严格文档的文档类型为:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">

XHTML was similar:

XHTML类似于:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

They required a DTD (Document Type Definition) because those old HTML versions were based on SGML, a format that defines the structure of a document.

他们需要DTD( 文档类型定义 ),因为那些旧HTML版本基于SGML(一种定义文档结构的格式)。

XHTML also required the html tag to have a namespace, like this:

XHTML还要求html标记具有名称空间,如下所示:

<html xmlns="http://www.w3.org/1999/xhtml">

Those doctype declarations always required you to save the DTD declaration somewhere, as it’s nearly impossible to memorize. Also, there were different DTDs for strict mode or transitional mode (which was less strict).

这些doctype声明始终要求您将DTD声明保存在某个位置,因为几乎无法记住。 同样,对于严格模式或过渡模式(不太严格),存在不同的DTD。

XHTML is an XML vocabulary, while HTML4 (and lower) is an SGML application. The current HTML, HTML5, is heavily inspired by HTML4, but is not an SGML application, and abandoned many of the strict rules of XHTML.

XHTML是XML词汇表,而HTML4(及更低版本)是SGML应用程序。 当前HTML(HTML5)在很大程度上受到HTML4的启发,但它不是SGML应用程序,并且放弃了许多严格的XHTML规则。

HTML5 is not based on SGML, but on its own standard, so the DTD is not required, and we benefit from this in this very simple declaration:

HTML5不是基于SGML,而是基于其自己的标准,因此不需要DTD,我们可以从以下非常简单的声明中受益:

<!DOCTYPE html>

翻译自: https://flaviocopes.com/doctype/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值