diff --git a/css/amp.css b/css/amp.css index 0bb95057f6da..a41212a1f318 100644 --- a/css/amp.css +++ b/css/amp.css @@ -17,9 +17,16 @@ /** * Horizontal scrolling interferes with embedded scenarios and predominantly * the result of the non-responsive design. + * + * Notice that it's critical that `overflow-x: hidden` is only set on `html` + * and not `body`. Otherwise, adding `overflow-x: hidden` forces `overflow-y` + * to be computed to `auto` on both the `body` and `html` elements so they both + * potentially get a scrolling box. See #3108 for more details. */ -html, body { +html { overflow-x: hidden !important; +} +html, body { height: auto !important; } diff --git a/examples/everything.amp.html b/examples/everything.amp.html index 071998d5a62d..36f00b839172 100644 --- a/examples/everything.amp.html +++ b/examples/everything.amp.html @@ -92,6 +92,18 @@ #amp-iframe:target { border: 1px solid green; } + + #breaker { + height: 100px; + background: green; + } + + #breaking { + height: 200px; + width: 200vw; + background: rgba(0, 0, 0, 0.5); + } + @@ -362,6 +374,10 @@

SVG

on-error-add-class="comic-amp-font-missing" on-load-add-class="comic-amp-font-loaded"> + +
+
+
diff --git a/src/service/viewport-impl.js b/src/service/viewport-impl.js index e0ae17403291..e6e2ab60f3b8 100644 --- a/src/service/viewport-impl.js +++ b/src/service/viewport-impl.js @@ -807,6 +807,7 @@ export class ViewportBindingNaturalIosEmbed_ { webkitOverflowScrolling: 'touch', }); setStyles(documentBody, { + overflowX: 'hidden', overflowY: 'auto', webkitOverflowScrolling: 'touch', position: 'absolute', diff --git a/test/functional/test-viewport.js b/test/functional/test-viewport.js index 3e4d3e77873d..acb3e1b918b6 100644 --- a/test/functional/test-viewport.js +++ b/test/functional/test-viewport.js @@ -711,6 +711,7 @@ describe('ViewportBindingNaturalIosEmbed', () => { const body = windowApi.document.body; expect(documentElement.style.overflowY).to.equal('auto'); expect(documentElement.style.webkitOverflowScrolling).to.equal('touch'); + expect(body.style.overflowX).to.equal('hidden'); expect(body.style.overflowY).to.equal('auto'); expect(body.style.webkitOverflowScrolling).to.equal('touch'); expect(body.style.position).to.equal('absolute');