gpt4 book ai didi

html - 元素上的类型 ="text/css"是强制性的吗?

转载 作者:太空狗 更新时间:2023-10-29 12:35:41 24 4
gpt4 key购买 nike

我正在尝试使用 Google Web Fonts,并且在官方网站上 it recommends使用 <link>标签包括 type属性,如下:

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

在官方 HTML5 样板网站中,他们忽略了 type属性

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

根据 this rather old answer , 在 HTML5 中 type <style> 上的属性是可选的在 <link> 上标记和强制性标签。

但是,没有type的版本attribule 在 W3C validator 上验证正常.

所以,是 type属性是否强制?

最佳答案

我在 official W3C HTML5 draft 上找到了答案:

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

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. (...)

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 (...).

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">

...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).

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.

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>属性,同一份文件指出:

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]

关于html - <link> 元素上的类型 ="text/css"是强制性的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17554665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com