doctype作用_doctype

doctype作用

Specifying the correct doctype of your web page is very important. Without it, the client (the web browser, iPhone, etc) will have no idea which version of HTML you are using to write the document, and will default to guessing how the HTML should be rendered. In many browsers, this is known as “Quirks” mode, and can result in pages displaying oddly. By specifying the doctype, we tell the client “try to render this document according to the standards of this specification”. That information is added at the very start of the page, as follows:

指定网页的正确文档类型非常重要。 没有它,客户端(Web浏览器,iPhone等)将不知道您使用哪种版本HTML编写文档,并且默认情况下会猜测应该如何呈现HTML。 在许多浏览器中,这被称为“ Quirks”模式,并且可能导致页面显示异常。 通过指定doctype,我们告诉客户“尝试根据规范的标准来呈现此文档”。 该信息将在页面的开始处添加,如下所示:

<!DOCTYPE html>

The first line for HTML5 – the doctype – tells the browser which version of HTML we are using on a page. You may wish to think of the doctype as a negotiation or an exchange of information between the page and the browser, much as you might, upon meeting a stranger in Switzerland, attempt words in several different languages before both parties settle on speaking English. In our case, our web page is saying “Hi. I can give you the information that follows as at least HTML 5.”

HTML5的第一行(即doctype )告诉浏览器我们在页面上使用HTML版本。 您可能希望将doctype视为页面和浏览器之间的协商或信息交换,就像您在瑞士遇到一个陌生人时,在双方决定讲英语之前,尝试用几种不同的语言来尝试该doctype一样。 在我们的例子中,我们的网页说“嗨。 我可以为您提供至少HTML 5以下的信息。”

The modern HTML5 doctype is unusual in that it doesn’t specify a version name or number: HTML is now a “living language” that is constantly under development and change. Version numbers are only used in the formal specification.

现代HTML5文档类型很不寻常,因为它没有指定版本名称或版本号:HTML现在是一种“生活语言”,并且一直在不断发展和变化。 版本号仅在正式规范中使用。

The doctype is required to validate the page, in order to check that the page has the right structure, and that browsers will understand it. Without a doctype, the validator has no idea what version of HTML you are using, or what rules to check your code against.

必须使用doctype验证页面,以便检查页面的结构正确,并且浏览器可以理解它。 没有doctype,验证器将不知道您使用的是哪个版本HTML,或检查代码所依据的规则。

翻译自: https://thenewcode.com/375/The-doctype

doctype作用

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值