AMP problem with responsive image: the amp-img tag cover the figcaption tag

748 Views Asked by At

I've got a problem with displaying image amp-img tag.

Here is the html source:

<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>

And here is how AMP rendered:

<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>

As you can see, the amp-img tag is covering the figcaption tag, making the rendered image be stretched to fill its figure. I tried object-fit: contain; to trick the stretch, but the whole image displayed wrong padding. So, am I doing it wrong? Can someone help me fix it. Thanks a lot

Detail console:

<!doctype html>
<html ⚡>
<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>

0

There are 0 best solutions below