2

Probably best explained with pictures:

Before the scroll bar appears (everything is fine):

enter image description here

After the scrollbar appears (headers offset)

enter image description here

Fiddle: https://jsfiddle.net/r2pmtL4g/

code
John Smith
  • 8,567
  • 13
  • 51
  • 74

2 Answers2

1

One way to approach this is simply set the width of the tbody to > 100% so that the tbody has extra width for creating the scrollbar. like this:

.outerTable tbody {
  height: calc(100vh - 150px);
  overflow-y: auto;
  overflow-x: hidden;
  width:102%;
}

Here is a fiddle.

Jonathan Chaplin
  • 2,442
  • 1
  • 18
  • 21
  • This didn't work for me. Now it causes the opposite problem where the headers are initially offset (before the scroll bar appears). Also when the scroll bar appears it's off-screen. – John Smith Jan 23 '18 at 16:21
  • 1
    I found this post, hopefully it helps you. https://stackoverflow.com/questions/45524214/how-do-i-stop-my-web-content-from-shifting-left-when-the-vertical-scrollbar-appe – Jonathan Chaplin Jan 23 '18 at 16:40
0

This worked for me. I only need to support Chrome so it's fine:

overflow-y: overlay;

https://jsfiddle.net/r2pmtL4g/8/

John Smith
  • 8,567
  • 13
  • 51
  • 74