I have a page with a sidebar that is 250px wide and a main content container that is 100% width to fill up the remaining space, sitting next to the sidebar. These items are flex-children with a parent flex container.
HTML:
<div className="flex-container">
<div className="sidebar">sidebar</div>
<div className="main-container">main container</div>
</div>
CSS:
.flex-container {
display: flex;
flex: 1;
}
.sidebar {
width: 250px;
}
.main-container {
width: 100%;
}
This works fine normally, but on one page I have a table which stretches the main content panel so that the page is more than 100% width which results in a horizontal scroll bar.
To get around this I have tried to calculate a fixed width for the content container with the following code:
.main-content {
width: calc(100vw - 250px);
}
This mostly works but the calculation is off by 17px, causing a smaller, but still existent horizontal scrollbar and I can't work out why. Is this due to the scrollbar width included in the vw calculation?
Is there a way around this?
If I take the width of the main-container and subtract it from the inner viewport width it leaves me with 233px of space, which is less than the 250px it should be, and has the 17px remainder.
I am using Google Chrome for testing, but any solution should be cross browser compliant.