html - 当图像实际上是图片标签时,如何为图像定义微数据标记?
问题描述
在http://schema.org/Product范围内,我想为图像定义标记。通常它看起来如下:
<img itemprop="image" src="/path-to-image.suffix" alt="image-description" />
但是,现代响应式页面使用该<picture>
标签。我试过了...
<picture itemprop="image">
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
但它似乎不被谷歌的结构化数据测试工具所接受。将它添加到<img>
标签中<picture>
对我来说似乎不正确,因为它没有突出整个上下文,因此忽略了图像以各种分辨率存在的事实......
标签的正确微数据图像标记是picture
什么?
解决方案
如果你想要一个 URL 值
您必须在元素上指定itemprop
属性img
,而不是在picture
元素上:
<picture>
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img itemprop="image" src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
href
原因是因为如果 Microdata 属性应该有一个 URL 作为值,即所有具有orsrc
属性的元素,则只能使用某些元素。
如果你想要一个ImageObject
值
您必须在元素上指定contentUrl
属性:img
<picture itemprop="image" itemscope itemtype="http://schema.org/ImageObject">
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img itemprop="contentUrl" src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
也允许itemprop
在source
元素(而不是img
元素)上指定,但它需要有一个属性。src
推荐阅读
- datatables - 数据表 js 的顺风
- javascript - 如何在数组中获取不同的对象:Javascript
- django - 在 Django 中正确设置自定义登录重定向
- web-applications - 如何允许一次性使用 Web 应用程序?
- r - arulesCBA 包中的分类
- vue.js - 添加到现有对象以使其具有反应性
- vite - 构建 vite 项目时出现分配给右值错误
- java - MySQL Workbench 没有“看到”来自 JDBC Java 程序的更新
- html - 我怎样才能使按钮宽度:当它在文本区域下方时为 100%
- r - 将 csv 文件读入 r 和循环内的函数,错误消息