Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-overflow/scrollable-overflow-abspos-in-inline-containing-block.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Test: scrollable overflow of an absolutely positioned box whose containing block is an inline box</title>
<meta name="assert" content="An absolutely positioned box at its static position, whose containing block is a relatively positioned inline box, contributes its actual position to the scrollable overflow of the scroll container, including when the inline box is wrapped in an anonymous block.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="stylesheet" href="/fonts/ahem.css">
<style>
.scroller {
position: relative;
overflow: auto;
font: 20px/1 Ahem;
width: 200px;
height: 100px;
}
.spacer {
height: 500px;
}
.abs {
position: absolute;
width: 10px;
height: 1000px;
}
.wide {
width: 1000px;
height: 10px;
}
</style>
<div id="tests"></div>
<script>
const inAnonymousBlock = { description: "inline box in an anonymous block", before: `<div class="spacer"></div>`, after: `<div></div>` };
const inScrollContainer = { description: "inline box in the scroll container's inline formatting context", before: "x<br>".repeat(25), after: "" };
const cases = [
{ configuration: inScrollContainer, style: "top: auto", axis: "block" },
{ configuration: inScrollContainer, style: "left: auto", axis: "inline", className: "wide" },
{ configuration: inAnonymousBlock, style: "left: auto", axis: "inline", className: "wide" },
];
const tests = document.getElementById("tests");
for (const testCase of cases) {
const scroller = document.createElement("div");
scroller.className = "scroller";
scroller.innerHTML = `${testCase.configuration.before}xx<span style="position: relative; margin-left: 50px">x<div class="abs ${testCase.className ?? ""}" style="${testCase.style}"></div>x</span>${testCase.configuration.after}`;
tests.append(scroller);
test(() => {
const scrollerRect = scroller.getBoundingClientRect();
const outOfFlowRect = scroller.querySelector(".abs").getBoundingClientRect();
if (testCase.axis == "block")
assert_approx_equals(scroller.scrollHeight, outOfFlowRect.bottom - scrollerRect.top, 1, "scrollHeight");
else
assert_approx_equals(scroller.scrollWidth, outOfFlowRect.right - scrollerRect.left, 1, "scrollWidth");
}, `${testCase.configuration.description}; absolutely positioned box '${testCase.style}'`);
}
tests.remove();
</script>