I have the following simple set-up:
document.getElementById('inner').addEventListener('click', ({ target }) => {
target.classList.add('match');
});
#container {
background: green;
overflow: auto;
width: 200px;
height: 100px;
}
#inner {
width: 210px;
height: 110px;
}
#inner.match {
width: 200px;
height: 100px;
}
<div id="container">
<div id="inner"></div>
</div>
Upon clicking the inner element, I'd expect the scrollbars on the parent to disappear since the two elements now have matching sizes. This works as expected in Firefox.
However the container element doesn't lose scrollbars in Chrome as can be seen in the below screenshot:
The scrollbars themselves create an offset large enough to create overflowing.
Is this a webkit-specific issue? Is there a cross-browser, reliable solution to this (seemingly trivial) issue?
I'm looking for a solution that doesn't change the parent's properties as my content (#inner
) will be placed in DOM I don't have control over.
So far I've tried hiding/showing and/or detaching/reinserting the element at different points of execution, but the problem persists, likely because the operations are simply optimized away.
The issue occurs both in Jsfiddle and in the Stack snippet.
The bug has been filed on Webkit Bugzilla.