New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Responsive Layout for <amp-img> BREAKS aspect ratio when nested in <amp-carousel> #1531
Comments
Yes, this is clearly a bug. We'll fix shortly. In the meantime, could you place each image in a |
Let me give it a go and see what happens. |
@johnnyshankman now it actually looks correct. Preserving the aspect ratio is actually what In case of 500x200 case where it's pinned to top, you can always assign a class to the parent In case of 300x450 where it's clipped - there's no easy way to address it via CSS, since CSS is a bit challenge when dealing with height. If you find a way - let me know. That being said, since you know the aspect ratios ahead of time - you should be able to match them. |
So you're telling me that if I tell an I don't mean to say that makes the carousel useless but I'm pretty sure there is no valid way to make this work since I'd need to either use The centering of the 500x200 is not an issue, as you have explained. I can fix that with CSS. So thank you for helping with that! |
|
Dang, that's a real game breaker for us. Well, I'll report back if I can manage to produce a working/valid solution. Unfortunately unless one of your engineers comes up with a working solution in mean time, I won't have more time to spike on this again for a few weeks which means you won't hear back from me for a little while. I'll continue to monitor this issue just in case that does happen though! crosses fingers |
Hmm. This is a pretty typical problem. What do you do today to resolve it? |
@johnnyshankman Forgot about this option. It's possible to use http://jsbin.com/vuxite/edit?html,css,output In a nutshell you have to see Let me know if this works for you. This would work for any replaced element: img, video, etc. |
@dvoytenko I eventually found that our API can pad the images via query parameters so I did some math in order to always pad the images into a square. I totally don't want to continue doing that though so I will try this solution first thing Monday morning and report back with my findings. The JSBin looks promising though!!!! Thank you for that! |
@dvoytenko Just kidding I got antsy. IT WORKS! Both of the solutions in the JS Bin works perfectly. 👍 The images maintain their aspect ratio and contain themselves inside the carousel box. I think the object-fit + layout="fill" workaround is great, and maybe should be documented because I'm sure tons of people will want this functionality from their slideshows/carousels. My final working responsive amp-lightbox with slideshow goes a little like this:
and in the CSS
|
Awesome. Yes. We will document. |
@johnnyshankman I've tried your approach and the carousel shows up on the top of the screen and not centered. Any other place I could chat with you? |
You can post a link to your document here or try us on slack https://github.com/ampproject/amphtml/blob/master/DEVELOPING.md#slack-and-mailing-list |
@dvoytenko Thanks! If the images have all the same size, the carousel shows on top: http://filmspot.pt/artigo/o-gerente-da-noite-canal-amc-estreia-minisserie-de-espionagem-8126/amp/ If the images have different sizes, I'm making the carousel width and height the maximum width and height of the several images, it still shows on top, but images are being clipped: http://filmspot.pt/artigo/imagens-da-antestreia-mundial-de-star-wars-o-despertar-da-forca-7854/amp/ Just remove /amp/ on both urls to see the desktop (or mobile, depending on device) version. |
@webdados Thanks for sharing the examples. These cases look fairly straightforward and not really related to images - the carousels themselves are not aligned vertically inside the lightboxes. One option you can do is to use
There are a number of other approaches, but I prefer Also, we are currently designing a carousel-based lightbox which should fit this case nicely in the future. Stay tuned! |
@dvoytenko I will stay tuned! Is flex fully supported by today's mobile devices? (I've implemented your CSS rules and still got the vertical images clipped on the Star Wars example) |
@webdados It's supported essentially everywhere, but you may need to add vendor-prefixed properties as well. This is typically done for you by most of the CSS tools, though. |
Should we mention in the See this SO question. @adewale's answer is now out of date. |
@dandv We may do so, yes. So far we resisted because it's easy not to notice the improper original image size issues with the default |
This still breaks if each image is wrapped in a div: http://jsbin.com/qukosutibo/edit?html,css,output Notice how the tall images are getting cut off. I need to wrap my images divs because eventually I'd like to include a caption below each one. |
@Flowgram
carousel1 has the width of 400, while the image's given ratio is 300:950. As the result, the image will be resized to have width 400 and height 950 * 400 / 300 = 1266. Then you apply I think in your case you want to make images to have the same size as the carousel (400x400 or layout=fill) and use |
@dvoytenko Thanks for getting back to me. Thing is, it works perfectly without the wrapping div. Height of each image is restricted to the carousel height regardless of the height passed in for each image, see carousel2 here: http://jsbin.com/fagigajoda/edit?html,css,output Eventually this is the markup that I'm aiming for:
|
This is because carousel forces each slide (an immediate child) to be sized by the carousel's size. The same rules cannot be applied to the children within the slide itself since we can't make assumption about the design. E.g. it maybe perfectly justifiable to have content of a slide overflow for some reason. The easiest change from your current sample is to update |
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.The text was updated successfully, but these errors were encountered: