amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-carousel cropping the item DOM height in desktop UA

Open uskay opened this issue 8 years ago • 4 comments

What's the issue?

When using amp-carousel in desktop UA && adding carousel item as non-amp-img DOM, since i-amphtml-slides-container has overflow-x: auto !important, height: 100% !important will be calculated minusing the scroll bar's height, which will end up to shorter container height and item being cropped.

An image like this... abc ...will end up showing like this in amp-carousel when the items are surrounded by <a> tag (<a href="/"><amp-img></amp-img></a>) abc Live example: AliExpress abc

How do we reproduce the issue?

Repro page: https://amp-carousel-size-test.glitch.me/

  1. Add carousel items as non-amp-img DOM e.g. <div>, <a>...
  2. Open the page in desktop UA

*If using Mac's trackpad, scrollbar is automatically hidden so you will need to use a mouse or reproduce by setting always to Show scroll bars. *If you remove padding-bottom: 20px from i-amphtml-slides-container, it's very clear that the scroll bar height is breaking the container height. abc

Suggestion

What do you think about simply inheriting i-amphtml-slides-container's height from parent rather than height: 100%? https://github.com/uskay/amphtml/commit/a99fc21023b380036c87037cab196129ef2fb192#diff-99d5d6d12e0d5695a02b76fbd2ef5353 abc

What browsers are affected?

All browsers (which will show scroll bars on overflow-x: auto)

Which AMP version is affected?

Powered by AMP ⚡ HTML – Version 1809142227020

uskay avatar Sep 25 '18 18:09 uskay

TIL, it is also defined here that height percentage will be calculated based on the padding box height when the element itself is absolute https://www.w3.org/TR/CSS22/visudet.html#the-height-property

I guess the definition padding box here is the same as Element.clientHeight?

inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight

-- adding comments start (13:07 JST) -- This spec could be more relavant

In the case of a scrollbar being placed on an edge of the element's box, it should be inserted between the inner border edge and the outer padding edge. Any space taken up by the scrollbars should be taken out of (subtracted from the dimensions of) the containing block formed by the element with the scrollbars. https://www.w3.org/TR/CSS22/visufx.html#propdef-overflow

-- adding comments end --

Which makes a lot of sense regarding this issue.

  • having overflow-x: auto might lead to showing a horizontal scroll bar e.g. using a mouse in desktop UA
  • having i-amphtml-slides-container as position: absolute && height: 100% will calculate the element height subtracting the horizontal scrollbar height (vs the item's actual size should be the same as the parent <amp-carousel>)
  • And having overflow-y: hidden will crop the item based on the calculated height above

Adding @aghassemi to this thread.

uskay avatar Sep 26 '18 02:09 uskay

Thanks for the detailed report and investigation!

dreamofabear avatar Sep 26 '18 14:09 dreamofabear

This issue hasn't been updated in awhile. @aghassemi Do you have any updates?

ampprojectbot avatar Jan 24 '19 03:01 ampprojectbot

Let's verify in the new carousel.

aghassemi avatar Jun 19 '19 15:06 aghassemi