Source code
Revision control
Copy as Markdown
Other Tools
<!doctype html>
<meta charset="utf-8">
<title>CSS Overflow: scrollbar-gutter on the root element</title>
<style>
html {
background-color: blue;
margin: 10px;
padding: 10px;
border: 5px solid black;
}
body {
margin: 10px;
padding: 10px;
border: 5px solid green;
}
#abspos {
position:absolute;
top:150px;
left: 0px;
background-color: green;
width: 80px;
height: 100px;
transform: translateZ(0);
}
p {
background-color: purple;
color: white;
}
</style>
<div id="outer" style="width: 100px; height: 100px; overflow: scroll; left: -200px; position: absolute;">
<div id="inner" style="width: 100%; height: 200%;"></div>
</div>
<script>
var outer = document.getElementById("outer");
var inner = document.getElementById("inner");
// Compute scrollbar gutter size and add it as margin to the root element
document.documentElement.style.marginRight = String((outer.offsetWidth - inner.offsetWidth) + 10) + "px";
</script>
<p id="content">Should not have space around me in the inline axis.</p>
<div id="abspos"> </div>