0

我在显示图像amp-img标记时遇到问题。

这是html源代码:

<figure>
<amp-img layout='responsive' width='600' height='400' alt="image  alternate"  src="/resize/600x338/NewFiles/Images/2021/08/23/2-1629682452101.jpg" class="" />
<figcaption>
<p>This is the description.</p>
</figcaption>
</figure>

以下是 AMP 的呈现方式:

<figure>
<amp-img layout="responsive" width="600" height="400" src="/resize/600x338/NewFiles/Images/2021/08/23/2-1629682452101.jpg" class="i-amphtml-element i-amphtml-layout-responsive i-amphtml-layout-size-defined i-amphtml-built i-amphtml-layout" i-amphtml-layout="responsive" i-amphtml-auto-lightbox-visited="" lightbox="i-amphtml-auto-lightbox-0" on="tap:amp-lightbox-gallery.activate"><i-amphtml-sizer slot="i-amphtml-svc" style="padding-top: 66.6667%;"></i-amphtml-sizer>
<figcaption>
<p>This is the description</p>
</figcaption>
<img decoding="async" src="/resize/600x600/NewFiles/Images/2021/08/23/2-1629682452101.jpg"  class="i-amphtml-fill-content i-amphtml-replaced-content" i-amphtml-auto-lightbox-visited="">
</amp-img>
</figure>

如您所见,amp-img标签覆盖了figcaption标签,使渲染的图像被拉伸以填充其figure。我试图object-fit: contain;欺骗拉伸,但整个图像显示错误的填充。那么,我做错了吗?有人可以帮我解决它。非常感谢

详细控制台:

<!doctype html>
<html ⚡&gt;
<head>
  <meta charset="utf-8">
  <title> Hello World</title>
  <script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>

  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <style amp-custom>
  </style>
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<div class="wrapper">
<figure>
<amp-img layout='responsive' width='600' height='400' alt="image  alternate"  src="https://img.freepik.com/free-photo/youtube-logo-3d-rendering-close-up-youtube-channel-promotion-template_1379-4797.jpg" class="" />
<figcaption>
<p>This is the description.</p>
</figcaption>
</figure>

</div>
</body>
</html>

4

0 回答 0