|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>An absolutely positioned box is still relaid out after a scrollable descendant gains a scrollbar</title> |
| 4 | +<link rel="help" href="https://drafts.csswg.org/css-overflow-3/#scrollbar-sizing"> |
| 5 | +<style> |
| 6 | +/* Avoid auto scrollbars on the viewport, because that might trigger re-layout |
| 7 | + (and thus hide bugs). */ |
| 8 | +body { overflow: hidden; } |
| 9 | + |
| 10 | +/* Always-on scrollbars, so that the scrollbar below really does consume space and |
| 11 | + change #scroller's content box. */ |
| 12 | +#scroller::-webkit-scrollbar { width: 15px; height: 15px; } |
| 13 | + |
| 14 | +/* A relatively positioned inline. It is both the parent of #inlineBlock and the |
| 15 | + containing block of #target, so the two branches below meet at this inline. */ |
| 16 | +#positionedInline { position: relative; } |
| 17 | + |
| 18 | +/* Inline-level, so that #positionedInline is its actual parent rather than an |
| 19 | + anonymous block. Fixed inline size, so its own size does not depend on its |
| 20 | + contents. */ |
| 21 | +#inlineBlock { display: inline-block; width: 600px; vertical-align: top; } |
| 22 | + |
| 23 | +/* Block-level flex container with an auto block size, so its size depends on its |
| 24 | + contents and a scrollbar appearing inside it can change that size. */ |
| 25 | +#flexContainer { display: flex; width: 500px; } |
| 26 | + |
| 27 | +/* Growing this along the main axis shrinks #positionedFlexItem, and with it |
| 28 | + #scroller. */ |
| 29 | +#flexItem { flex: 0 0 auto; width: 100px; height: 30px; } |
| 30 | + |
| 31 | +#positionedFlexItem { position: relative; flex: 1 1 auto; } |
| 32 | + |
| 33 | +/* Out of flow, and its inline size follows #positionedFlexItem. The scrollbar |
| 34 | + therefore appears as a consequence of the flex layout, rather than as a |
| 35 | + consequence of a style change on #scroller or its contents. */ |
| 36 | +#scroller { position: absolute; top: 0; left: 0; width: 100%; height: 60px; overflow-x: auto; overflow-y: hidden; } |
| 37 | +#overflowingContent { width: 300px; height: 20px; } |
| 38 | + |
| 39 | +/* #target's containing block, also inline-level under #positionedInline. */ |
| 40 | +#targetContainingBlock { display: inline-block; position: relative; width: 300px; height: 120px; vertical-align: top; } |
| 41 | +#target { position: absolute; top: 0; left: 0; width: 100px; height: 20px; } |
| 42 | +</style> |
| 43 | + |
| 44 | +<span id="positionedInline"><span id="inlineBlock"><div id="flexContainer"><div id="flexItem"></div><div id="positionedFlexItem"><div id="scroller"><div id="overflowingContent"></div></div></div></div></span><span id="targetContainingBlock"><div id="target"></div></span></span> |
| 45 | + |
| 46 | +<script src="/resources/testharness.js"></script> |
| 47 | +<script src="/resources/testharnessreport.js"></script> |
| 48 | +<script> |
| 49 | +// #positionedFlexItem is 400px wide to begin with, so #scroller is 400px and its |
| 50 | +// 300px of content does not overflow. |
| 51 | +document.body.offsetHeight; |
| 52 | + |
| 53 | +// Growing #flexItem shrinks #positionedFlexItem, and therefore #scroller, to 50px. |
| 54 | +// The 300px of content now overflows, so a horizontal scrollbar appears while |
| 55 | +// #flexContainer is being laid out. |
| 56 | +flexItem.style.width = "450px"; |
| 57 | +document.body.offsetHeight; |
| 58 | + |
| 59 | +test(() => { |
| 60 | + assert_greater_than(scroller.offsetHeight - scroller.clientHeight, 0, |
| 61 | + "a horizontal scrollbar should consume block-axis space"); |
| 62 | +}, "A horizontal scrollbar appears inside the flex container during its layout"); |
| 63 | + |
| 64 | +test(() => { |
| 65 | + target.style.height = "80px"; |
| 66 | + assert_equals(target.offsetHeight, 80); |
| 67 | +}, "An out-of-flow box under the same positioned inline is relaid out after the scrollbar change"); |
| 68 | +</script> |
0 commit comments