Html HTML5 中的 <link> 是否需要 type="text/css"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7715953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do we need type="text/css" for <link> in HTML5
提问by Jitendra Vyas
Possible Duplicate:
Is type=“text/css” necessary in a <link> tag?
Do we need type="text/css"
for <link>
tag in HTML5?
我们是否需要type="text/css"
为<link>
在HTML5标签?
采纳答案by Nathan MacInnes
The HTML5 specsays that the type
attribute is purely advisory and explains in detail how browsers should act if it's omitted (too much to quote here). It doesn't explicitly say that an omitted type attribute is either valid or invalid, but you can safely omit it knowing that browsers will still react as you expect.
在HTML5规范说的type
属性是纯粹的咨询,并详细解释了,如果它被省略(太多在这里引用)的浏览器应该如何行动。它没有明确说明省略的类型属性是有效的还是无效的,但是您可以放心地省略它,因为浏览器仍会按照您的预期做出反应。
回答by Sanooj
Don't need to specify a type
value of “text/css”
不需要指定type
值“text/css”
Every time you link to a CSS file:
每次链接到 CSS 文件时:
<link rel="stylesheet" type="text/css" href="file.css">
You can simply write:
你可以简单地写:
<link rel="stylesheet" href="file.css">
回答by ?ime Vidas
For LINK elements the content-type is determined in the HTTP-response so the type
attribute is superfluous. This is OK for all browsers.
对于 LINK 元素,内容类型在 HTTP 响应中确定,因此该type
属性是多余的。这适用于所有浏览器。
回答by cHao
You don't really need it today, because the current standard makes it optional -- and every useful browser currently assumes that a style sheet is CSS, even in versions of HTML that considered the attribute "required".
您今天并不真正需要它,因为当前的标准使它成为可选的——并且每个有用的浏览器当前都假定样式表是 CSS,即使在认为属性“必需”的 HTML 版本中也是如此。
With HTML being a "living standard" now, though -- and thus subject to change -- you can only guarantee so much. And there's no new DTD that you can point to and say the page was written for that version of HTML, and no reliable way even to say "HTML as of such-and-such a date". For forward-compatibility reasons, in my opinion, you should specify the type.
尽管 HTML 现在是“生活标准”——因此可能会发生变化——你只能保证这么多。并且没有新的 DTD 可以指向并说该页面是为该版本的 HTML 编写的,甚至没有可靠的方法可以说“HTML 作为某某日期”。出于向前兼容的原因,在我看来,您应该指定类型。