Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AMP-Carousel with varying image dimensions

Tags:

amp-html

I'm struggling to create an AMP-Carousel with images which have varying dimensions. I want to scale the images in the carousel to a fixed height & an automatic width.

The examples provided in the docs all have the same width/height.

I've tried leaving out the width for the amp-img elements & using layout="fixed-height" but that didn't work at all. The docs are very confusing.

<amp-carousel width=500 height=300>
    <amp-img src="http://placehold.it/200x600" width=200 height=600></amp-img>
    <amp-img src="http://placehold.it/700x550" width=700 height=550></amp-img>
    <amp-img src="http://placehold.it/340x410" width=340 height=410></amp-img>
</amp-carousel>

I've created a js-fiddle to show you what I've got & what I want

https://jsfiddle.net/ag38afa7/

Edit:

The styles are not consistent with the docs or I don't get them?
On the amp-carousel page it says: Layout not supported for: responsive but on the demo page the amp-img elements have layout="responsive"
https://ampbyexample.com/components/amp-carousel/

like image 350
Brian G. Bell Avatar asked Mar 04 '16 11:03

Brian G. Bell


Video Answer


1 Answers

You have to use the fixed-height layout and give carousel and all images the same height. The width needs to be updated accordingly to keep the aspect ratio. Example:

<amp-carousel height=300 layout="fixed-height">
    <amp-img src="http://placehold.it/200x600" width=100 height=300></amp-img>
    <amp-img src="http://placehold.it/700x550" width=381 height=300></amp-img>
    <amp-img src="http://placehold.it/340x410" width=248 height=300></amp-img>
</amp-carousel>

Automatically adjusting the width is currently not supported.

like image 56
Sebastian Benz Avatar answered Oct 11 '22 14:10

Sebastian Benz