属性属性的 HTML 验证错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2704942/
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
Html validation error for property attribute
提问by Castor
I am using few facebook social plugins and I am using the meta header. When validating the page, the W3C validator is throwing the error -> "Error: there is no attribute "property".
我使用的 Facebook 社交插件很少,我使用的是元标题。验证页面时,W3C 验证器抛出错误 ->“错误:没有属性“属性”。
I am using the XHTML Transitional doctype - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
我正在使用 XHTML 过渡文档类型 - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Pls Suggest if I have to change the doctype to something else.
请建议我是否必须将文档类型更改为其他内容。
回答by bobince
Facebook's plugins use Open Graph, which is built on RDFa. It's RDFa that adds the property
attribute to elements. Without this addition, plain HTML has no such attribute. (If you ask me, it's a strange design to add a new attribute without namespacing it, and to re-use half of a <meta>
tag. But no-one did.)
Facebook 的插件使用基于 RDFa 构建的Open Graph。RDFa 将property
属性添加到元素。没有这个添加,纯 HTML 没有这样的属性。(如果你问我,在没有命名空间的情况下添加新属性并重复使用<meta>
标签的一半是一种奇怪的设计。但没有人这样做。)
To validate XHTML-with-RDFa, you'll need the DOCTYPE:
要验证 XHTML-with-RDFa,您需要 DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
This means you will have to be writing valid XHTML 1.1. More
这意味着您必须编写有效的 XHTML 1.1。更多的
回答by albert
In order for a document to claim that it is a conforming HTML+RDFa document, it must provide the facilities described as mandatory in this section. The document conformance criteria are listed below, of which only a subset are mandatory:
为了让文档声称它是符合 HTML+RDFa 的文档,它必须提供本节中描述为强制性的设施。下面列出了文档一致性标准,其中只有一个子集是强制性的:
- All document conformance requirements stated as mandatory in the HTML5 specification must be met.
- There should be a
version
attribute on thehtml
element. The value of the version attribute should beHTML+RDFa 1.0
if the document is a non-XML mode document, orXHTML+RDFa 1.0
if the document is a XML mode document. - There may be a link element contained in the head element that contains profile for the the
rel
attribute and http://www.w3.org/1999/xhtml/vocabfor thehref
attribute.
- 必须满足 HTML5 规范中规定的所有文档一致性要求。
- 元素
version
上应该有一个属性html
。version 属性的值应该是HTML+RDFa 1.0
文档是否为非 XML 模式文档,或者XHTML+RDFa 1.0
文档是否为 XML 模式文档。 - 有可能是包含天寒的装在头部元素的链接元素
rel
属性和http://www.w3.org/1999/xhtml/vocab的href
属性。
Example:
例子:
<html version="HTML+RDFa 1.1" lang="en">
<head>
<title>Example Document</title>
</head>
<body>
<p>Moved to <a href="http://example.org/">example.org</a>.</p>
</body>
</html>
回答by timofey.com
As Open Graphsuggests, if you're using HTML5, you're better off just using a prefix attribute like this:
正如Open Graph 所建议的那样,如果您使用的是 HTML5,那么最好只使用这样的前缀属性:
<!doctype html>
<html prefix="og: http://ogp.me/ns#">
<head>
<title>HTML5 site</title>
<meta property="og:title" content="The Rock" />
</head>
<body>
</body>
</html>
You can leave the doctype as is and it will validate.
您可以保留 doctype 原样,它会验证。
This approach has also been recommendedby an Open Graph developer.
Open Graph 开发人员也推荐了这种方法。