is type =" text / css"必须在< link>元件? [英] Is type="text/css" mandatory on the <link> element?

查看:184
本文介绍了is type =" text / css"必须在< link>元件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google网页字体,并在官方网站上它使用包含类型属性的< link> 标签建议,如下所示:

I'm trying to use Google Web Fonts, and on the official site it recommends using a <link> tag including the type attribute, as following:

<link href='http://fonts.googleapis.com/css?family=Ubuntu:400,700' rel='stylesheet' type='text/css'>`



在正式的HTML5样板网站中, c $ c> type 属性

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,700">

根据这个相当老的回答,在HTML5中类型属性在< style> 标记是可选的并且在< link> 标记上是强制性的。

According to this rather old answer, in HTML5 the type attribute is optional on the <style> tag and mandatory on the <link> tag.

但是,没有类型属性的版本在 W3C验证器

However, the version without the type attribule validates fine on the W3C validator.

所以,类型属性是否为强制性的?

So, is the type attribute mandatory or not?

推荐答案

我发现了官方W3C HTML5草稿


type属性给出了链接资源的MIME类型。 它是
纯粹咨询
。该值必须是有效的MIME类型。

The type attribute gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type.

对于外部资源链接,type属性用作对
用户代理的提示,以便他们可以避免提取资源他们不支持
。如果属性存在,那么用户代理必须假定
资源是给定类型的(即使它不是有效的
MIME类型,例如空字符串)。如果省略该属性,但
外部资源链接类型定义了一个默认类型,则
用户代理必须假定该资源是该类型。 (...)

For external resource links, the type attribute is used as a hint to user agents so that they can avoid fetching resources they do not support. If the attribute is present, then the user agent must assume that the resource is of the given type (even if that is not a valid MIME type, e.g. the empty string). If the attribute is omitted, but the external resource link type has a default type defined, then the user agent must assume that the resource is of that type. (...)

用户代理不能考虑类型属性的权威性 - 在
获取资源时,用户代理不能使用type属性
确定其实际类型。只有实际类型(...)。

User agents must not consider the type attribute authoritative — upon fetching the resource, user agents must not use the type attribute to determine its actual type. Only the actual type (...).

样式表链接类型定义了处理资源的
Content-Type元数据的规则。 (...)

The stylesheet link type defines rules for processing the resource's Content-Type metadata. (...)

如果文档包含标签如下的样式表链接:

If a document contains style sheet links labeled as follows:

 <link rel="stylesheet" href="A" type="text/plain">
 <link rel="stylesheet" href="B" type="text/css">
 <link rel="stylesheet" href="C">

...仅支持CSS样式表的兼容UA将
获取B和C文件,并跳过A文件(因为text / plain不是
CSS样式表的MIME类型)。

...then a compliant UA that supported only CSS style sheets would fetch the B and C files, and skip the A file (since text/plain is not the MIME type for CSS style sheets).

对于文件B和C,它将检查
服务器返回的实际类型。对于那些以text / css格式发送的,它将应用
样式,但是对于标记为text / plain或任何其他类型的样式,
不会。

For files B and C, it would then check the actual types returned by the server. For those that are sent as text/css, it would apply the styles, but for those labeled as text/plain, or any other type, it would not.

如果两个文件之一没有Content-Type元数据,
或者语法不正确的类型,比如Content-Type:null,那么
是默认类型因为
默认类型是text / css,所以样式表将被应用

If one of the two files was returned without a Content-Type metadata, or with a syntactically incorrect type like Content-Type: "null", then the default type for stylesheet links would kick in. Since that default type is text/css, the style sheet would nonetheless be applied.

对于< style> 属性,同一文档规定:

For the <style> attribute, the same document states:


type属性给出了样式语言。如果属性是
存在,那么它的值必须是指定样式
语言的有效MIME类型。不能指定charset参数。类型属性的默认
值是text / css,如果属性是
,则使用缺省值。 [RFC2318]

The type attribute gives the styling language. If the attribute is present, its value must be a valid MIME type that designates a styling language. The charset parameter must not be specified. The default value for the type attribute, which is used if the attribute is absent, is "text/css". [RFC2318]

这篇关于is type =&quot; text / css&quot;必须在&lt; link&gt;元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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