How can you add horizontal padding to an inline-block div that has a vertical scrollbar (like a sidebar) without getting a horizontal scrollbar? I'm looking for a solution which doesn't require a fixed width (just uses the width of the content of the sidebar).
I tried putting the padding in the inner div and the scrollbar on the outer div, thinking it would then make room for both, but the scrollbar still steps on the right padding.
Example:
html, body {
margin: 0; padding: 0;
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
overflow: hidden;
}
#div1 {
display: inline-block;
height: 100%;
overflow-y: auto;
}
#div2 {
display: inline-block;
padding: 0 10px;
height: 100%;
}
<div id='div1'>
<div id='div2'>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
text<br>
</div>
</div>
JSFiddle: https://jsfiddle.net/msxjL52d/2/