Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<title>scroll{Width,Height} shouldn't account for collapsed margins, in order not to report unnecessary overflow</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#target div {
height: 20px;
min-width: 20px;
background-color: green;
margin: 20px 10px;
}
</style>
<div id="target">
<div>
<div></div>
</div>
<div></div>
<div></div>
<div></div>
</div>
<script>
let target = document.getElementById("target");
// "clip" is not really scrollable, but should match as well.
for (let overflow of ["visible", "hidden", "auto", "scroll", "clip"]) {
for (let padding of ["0", "2px"]) {
for (let border of ["0", "3px solid"]) {
for (let display of ["flex", "block", "flow-root", "inline-block", "inline-flex", "grid", "inline-grid"]) {
test(function() {
target.style.overflow = overflow;
target.style.display = display;
target.style.border = border;
target.style.padding = padding;
let sh = target.scrollHeight;
let sw = target.scrollWidth;
let ch = target.clientHeight;
let cw = target.clientWidth;
assert_equals(sh, ch, "scrollHeight should match clientHeight, since there's no overflow");
assert_equals(sw, cw, "scrollWidth should match clientWidth, since there's no overflow");
}, `scroll{Width,Height} with margins should match client{Width,Height} if there would be no overflow width overflow: ${overflow}, padding: ${padding}, border: ${border}, display: ${display}`);
}
}
}
}
</script>