可以在DOCTYPE声明之前出现注释吗? [英] Can comments appear before the DOCTYPE declaration?

查看:167
本文介绍了可以在DOCTYPE声明之前出现注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在HTML代码的最前面加上一个注释(<! - this - > style),在DOCTYPE声明之前。这是否符合标准?是主流浏览器支持吗?

I would like to place a comment (<!-- this --> style) at the very top of my HTML code, preceding the DOCTYPE declaration. Does this conform to the standards? Is it supported by the major browsers? Are there any pitfalls in doing this?

推荐答案

首先编写DOCTYPE是最好的做法。

Writing the DOCTYPE first is certainly best practice.

我记得很奇怪的问题,很久很久以前,一些浏览器(可能是IE6)忽略了一个DOCTYPE,因为有一些看起来无辜的前面 - 我认为只是空白,但也许这是一个评论。在任何情况下,这是一个可怕的,可怕的错误跟踪,并没有任何好的理由在DOCTYPE之前有评论或空格。

I remember strange problems a long, long time ago where some browser (probably IE6) ignored a DOCTYPE because there was something seemingly innocent before it - I think just whitespace, but maybe it was a comment. In any case, it was a horrible, horrible bug to have to track down, and there's certainly never any good reason to have comments or whitespace before the DOCTYPE.

写DOCTYPE首先是,我想说,只是经验的网络开发人员,以避免可怕的,难以捉摸的错误。

Writing the DOCTYPE first is, I'd say, just something experienced web developers do to avoid horrible, elusive bugs.

这篇关于可以在DOCTYPE声明之前出现注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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