问题
In all examples around the web I see Microdata properties itemscope and itemtype being applied to div elements, like so:
<div itemscope itemtype =\"http://schema.org/Movie\">
<h1 itemprop=\"name\">Avatar</h1>
<span>Director: <span itemprop=\"director\">James Cameron</span> (born August 16, 1954)</span>
<span itemprop=\"genre\">Science fiction</span>
<a href=\"../movies/avatar-theatrical-trailer.html\" itemprop=\"trailer\">Trailer</a>
</div>
But can Microdata be applied on any other element, in my case I want to apply it to a list item:
<ul>
<li itemscope itemtype =\"http://schema.org/Movie\">
<h1 itemprop=\"name\">Avatar</h1>
<span>Director: <span itemprop=\"director\">James Cameron</span> (born August 16, 1954)</span>
<span itemprop=\"genre\">Science fiction</span>
<a href=\"../movies/avatar-theatrical-trailer.html\" itemprop=\"trailer\">Trailer</a>
</li>
</ul>
Are there any known problems with this?
回答1:
Simply put, "Yes". Check out the Google page yourself to see them use it in different tags: https://support.google.com/webmasters/answer/176035?hl=en
回答2:
You can use every HTML5 element for Microdata …
Microdata defines 5 new attributes for HTML5:
itemiditempropitemrefitemscopeitemtype
Let’s see where they can be used. Section 5.2 says:
Every HTML element may have an
itemscopeattribute specified.
So every element can have itemscope. Further on it says:
Elements with an
itemscopeattribute may have anitemtypeattribute specified
So if it has itemscope (and we learned that every element can have it), it can have itemtype, too. Next:
Elements with an
itemscopeattribute and anitemtypeattribute […] may also have anitemidattribute specified
If it has itemscope and itemtype, it can have itemid, too. And:
Elements with an
itemscopeattribute may have anitemrefattribute specified
If it has itemscope, it can have itemref.
Only itemprop is missing now. It’s defined in Section 5.3:
Every HTML element may have an
itempropattribute specified
So itemprop can also be used on every element.
(Note that Microdata (W3C Note) refers to the HTML5 spec for defining what a "HTML element" is, so essentially "HTML element" means "HTML5 element".)
… but some elements get a different content model (when itemprop is used)
See 8.1 Content models.
For example:
hrefbecomes a required attribute foraandareadatabecomes a required attribute foriframe- the attributes
name,http-equivandcharsetare no longer allowed onmeta
… and some elements have special rules for determining the property value (when itemprop is used)
See 5.4 Values.
For example:
Special rules for links. Here foobar’s value is the URL http://example.com/, not the string Link:
<a href="http://example.com/" itemprop="foobar">Link</a>
Here foobar’s value is 5, not 10:
<data value="5" itemprop="foobar">10</data>
And search engines should know this.
If Google or other search engine services support it can’t be answered definitely, as nothing can be answered with certainty when it comes to third party services that keep their code hidden. Even if they (seem to) support it today, we can’t know what will happen tomorrow. So such questions are usually not appropriate for Stack Overflow.
However, there is no reason to assume that search engines wouldn’t support it.
回答3:
Adding to Jeremy Miller's answer:
Microdata essentially forms objects. In valid HTML, an element with the itemscope attribute contains all of the microdata associated with it. Also, the scope of each element with an itemprop is enough to contain all data necessary for that property.
Imagine replacing each itemscope element with the item itself; and replacing each itemprop element with the property itself, and its value. (Think XML)
In your example, the item would look like this:
<movie>
<name>Avatar</name>
<director>James Cameron</director>
<genre>Science fiction</genre>
<trailer>Trailer</trailer>
</movie>
This structure of itemscopes and itemprops can be applied to any suitable hierarchy of HTML elements, regardless of what elements they are. The long-winded answer is still yes, but I hope this has helped you understand how microdata is interpreted.
Also, I'm guessing your example is from here, but I suggest you give at least items 1a-1d a quick read.
来源:https://stackoverflow.com/questions/20880229/can-microdata-be-applied-on-any-type-of-html-element