Html 元素链接缺少必需的属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18549726/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:52:57  来源:igfitidea点击:

Element link is missing required attribute property

html

提问by no9

<!DOCTYPE html>
...
<link rel='stylesheet' id='basecss-css' href='http://www.someurl.com/modules/14ce1e21/peadig-eucookie.css' type='text/css' media='all' />

Why is the validator (http://validator.w3.org/) rejecting this? What attribute is "required" that I am not aware of?

为什么验证器(http://validator.w3.org/)拒绝这个?哪些属性是我不知道的“必需”属性?

The error:

错误:

Error Line 408, Column 142: Element link is missing required attribute property. …/modules/14ce1e21/peadig-eucookie.css' type='text/css' media='all' /> Attributes for element link: Global attributes href crossorigin rel media hreflang type sizes Also, the title attribute has special semantics on this element.

错误行 408,第 142 列:元素链接缺少必需的属性属性。…/modules/14ce1e21/peadig-eucookie.css' type='text/css' media='all' /> 元素链接的属性:全局属性 href crossorigin rel media hreflang 类型大小 此外,title 属性对此有特殊语义元素。

回答by hawkeye126

Add

添加

property='stylesheet'

if you do not want to move your link to the <head>of the document.

如果您不想将链接移至<head>文档的 。

<link rel='stylesheet' property='stylesheet' id='basecss-css'  href='http://www.someurl.com/modules/14ce1e21/peadig-eucookie.css' type='text/css' media='all' />

回答by Jukka K. Korpela

The advice from @stevelove is apparently the practical solution, but here's a theoretical answer to the “why” question:

@stevelove 的建议显然是实用的解决方案,但这里是“为什么”问题的理论答案:

Although a linkelement is unconditionally invalid in bodyin older HTML specifications, HTML5 has more permissive rules. According to HTML 5.1 Nightly (which is more or less what the validator tries to keep up with), the linkelementis allowed in the document body, too (wherever phrasing content is allowed), provided that it has an itempropattribute. This seems to make the error message even more puzzling. Part of the explanation is that the validator is actually validating against HTML5 + RDFa, and RDFa defines the propertyattribute. The problem still remains what specific RDFa definition the validator is checking against, since the definition would need to redefine rules for HTML, too.

尽管在旧的 HTML 规范中link元素是无条件无效的body,但 HTML5 有更宽松的规则。根据 HTML 5.1 Nightly(这或多或少是验证器试图跟上的内容),该link元素也被允许出现在文档正文中(只要它有一个itemprop属性)(任何允许措辞的内容)。这似乎使错误信息更加令人费解。部分解释是验证器实际上是针对 HTML5 + RDFa 进行验证,而 RDFa 定义了该property属性。问题仍然是验证器检查的具体 RDFa 定义是什么,因为该定义也需要为 HTML 重新定义规则。

The information in the error message is outdated, anyway. Error messages are apparently not updated as fast as the basic functionality of the validator.

无论如何,错误消息中的信息已经过时。错误消息显然没有验证器的基本功能更新得那么快。

回答by stevelove

Is your <link>inside the <body>? If so, try putting it in the <head>at the top of the document.

是你<link>里面的<body>吗?如果是这样,请尝试将其放在<head>文档的顶部。

回答by sideshowbarker

W3C HTML5 validator maintainer here. As pointed out in another answer, in addition to checking requirements in the HTML5 spec itself, the validator also checks against requirements in the HTML+RDFa 1.1 spec:

W3C HTML5 验证器维护者在这里。正如另一个答案中所指出的,除了检查 HTML5 规范本身的要求外,验证器还检查 HTML+RDFa 1.1 规范中的要求:

http://www.w3.org/TR/html-rdfa/

http://www.w3.org/TR/html-rdfa/

And while the HTML spec itself says linkis normally not allowed in the body*, the RDFa spec says that if a linkelement has a propertyattribute, it is allowed in the body.

虽然 HTML 规范本身说link通常不允许在 body* 中,但 RDFa 规范说如果一个link元素有一个property属性,它在 body 中是允许的。

So that validator message is basically saying,「The linkelement is only allowed here if it has a propertyattribute. But this particular linkelement doesn't have a propertyattribute.」

所以验证器消息基本上是在说,“该link元素仅在具有property属性的情况下才被允许使用。但是这个特殊的link元素没有property属性。”

* The HTML spec itself does also say that the linkelement is allowed in the body if it has an itempropattribute—but only if the linkelement doesn't have a relvalue. (itempropis “Microdata” attribute whose purpose is basically the same as the RDFa propertyattribute).

* HTML 规范本身也说,如果该元素link具有itemprop属性,则该link元素在正文中是允许的——但前提是该元素没有rel值。(itemprop是“Microdata”属性,其目的与RDFaproperty属性基本相同)。

So we have two different attributes that both independently affect where in a document the linkelement is allowed to appear, and that complicates the checking logic in the validator in a way that makes it difficult to emit a better, more helpful error message for this case.

因此,我们有两个不同的属性,它们都独立地影响link元素在文档中允许出现的位置,并且使验证器中的检查逻辑复杂化,使得在这种情况下很难发出更好、更有用的错误消息。

回答by h3nr1ke

Just for future needs, here is my comment:

只是为了将来的需要,这是我的评论:

In the w3c pagewe have the following commentary:

w3c 页面中,我们有以下评论:

If the rel attribute is used, the element is restricted to the head element. When used with the itemprop attribute, the element can be used both in the head element and in the body of the page, subject to the constraints of the microdata model.

如果使用 rel 属性,则该元素仅限于 head 元素。当与 itemprop 属性一起使用时,该元素可以在 head 元素和页面正文中使用,但受微数据模型的约束。

So the error can be solved by changing relfor itemprop, because relis to be used in the head and itempropcan be used in the body.

所以错误可以通过改变relfor来解决itemprop,因为rel是用在头部,itemprop可以用在身体。

Hope it helps somebody.

希望它可以帮助某人。

回答by Randy Greencorn

It wants it to be in your head. However, if the css is not too important to load right away, you will get google's pagespeed tool telling you to put it in the bottom of the body.

它希望它在你的脑海中。但是,如果 css 不是太重要而不能立即加载,您将得到 google 的 pagespeed 工具,告诉您将其放在正文的底部。

As an example, I use one of the jquery themes (redmond) to style my autocomplete. No need to put this in the top of my page as it will just slow down everything else.

例如,我使用 jquery 主题 (redmond) 之一来设置自动完成的样式。无需将其放在我的页面顶部,因为它只会减慢其他一切。

So, don't worry too much about perfect w3c validation.

所以,不要太担心完美的 w3c 验证。