amp-img error: Layout not supported for: container

amp-img error: Layout not supported for: container

正在尝试验证我的 amp-img。在这个例子中:http://staging.laineygossip.com/Sasha-Celeb-Finds-Sienna-Miller/Lifestyle/24695/amp#development=1

我收到错误:Layout not supported for: container
在控制台中,错误是:The specified layout 'CONTAINER' is not supported by tag 'amp-img'

不确定这个错误是什么意思。

到目前为止,我在文档中找不到与此错误消息相关的任何内容。

container 不受 <amp-img> 中的 layout 属性支持。 AMP Docs 提供了您可以使用的受支持布局列表。

根据 google AMP 文档,支持的布局:

填充、固定、固定高度、弹性项目、无显示、响应式

另请参阅此示例,我认为您不需要在布局类型周围加上引号:https://ampbyexample.com/samples_templates/news_article/

所以它应该看起来像这样:

  <figure>
    <amp-img src="/img/landscape_village_1280x720.jpg"
      width=1280
      height=768
      layout=responsive></amp-img>
   <figcaption>Here is a responsive image.</figcaption>
 </figure>

如果没有设置宽度和高度属性,Amp 默认为布局="container"。 所以即使你没有设置布局,你也会得到这个错误。

在我回复时,不支持布局的 amp-img 也是这种情况="container" - 因此您的错误。

Layout Documentation

通过添加宽度和高度或指定适当的布局来解决您的问题。

如果我们没有提及 amp 图片的宽度和高度,就会出现此错误。如果没有为 amp 图像指定宽度和高度属性(amp 图像必须预先指定明确的宽度/高度大小,以便在不获取图像的情况下可以知道宽高比),推断的布局是容器,它是相同 AMP Docs 的布局不受支持,因此发生错误。