Solvedamphtml Responsive Layout for <amp-img> BREAKS aspect ratio when nested in <amp-carousel>
johnnyshankman posts at
26 Answers
Share
Original✔️Accepted Answer
@johnnyshankman Forgot about this option. It's possible to use layout=responsive
or layout=fill
for replaced content such as images to preserve aspect ratio in slides. Here's an example:
http://jsbin.com/vuxite/edit?html,css,output
In a nutshell you have to see object-fit: contain
on the encapsulated IMG element.
Let me know if this works for you. This would work for any replaced element: img, video, etc.
Related Issues:
3
amphtml Responsive Layout for <amp-img> BREAKS aspect ratio when nested in <amp-carousel>
@johnnyshankman Forgot about this option This bug breaks <amp-carousel>s containing <amp-img>s of di...
3
amphtml amp-ad 'Ad' attribution does not collapse if no ad returned
Use a amp-ad:before selector? When the ad collapses the before will too. What's the issue? amp-ad 'A...
This bug breaks
<amp-carousel>
s containing<amp-img>
s of different sizes completely.The code block in question
Everything works fine but the images fill the box without regards to aspect ratio, even with the declared
height
andwidth
inside of the AMP-HTML tag. Normally when I declare a height and width and useresponsive
as the layout the<amp-img>
maintains its aspect ratio.