skip to Main Content

I have a table over which I need to be able to scroll vertically as a whole. (so with the scrollbar on the right, you scroll the left AND right column at the same time)

Inside this table there are 2 columns over which I need to be able to scroll horizontally (individually).
But the 2 horizontal scrollbars disappear at the bottom of the table because of the vertical scrollbar.

How do I get those to be visible at all times?

Here’s the fiddle Example: Fiddle Example

enter image description here

#data {
  background: grey;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  
  height: 400px;
  width: 500px;
}

#splitter {
  display: flex;
  flex-direction: row;
  background: darkgrey;
  overflow-x: hidden;
  overflow-y: auto;
  align-items:start;
}

#right-content {
  background: Gainsboro;
  overflow-x: auto;
  overflow-y: hidden;
}

#left-content {
  background: Gainsboro;
  overflow-x: auto;
  overflow-y: hidden;
}

div {
  margin: 10px;
}

p {
  padding: 2px;
  margin: 0px;
}
<div id="data">
  <div id="splitter">
    <div id="left-content">
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
      <p>LeftColumnLeftColumn</p>
    </div>
    <div id="right-content">
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
      <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>          
    </div>
  </div>
</div>

2

Answers


  1. You can use like this

    #data {
      background: grey;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      width: 500px;
    }
    
    #splitter {
      display: flex;
      flex-direction: row;
      background: darkgrey;
      align-items:start;
    }
    
    #right-content {
        background: Gainsboro;
        overflow: auto;
        width: 100%;
        white-space: nowrap;
        height: 400px;
    }
    
    #left-content {
        background: Gainsboro;
        overflow: auto;
        white-space: nowrap;
        height: 400px;
    }
    
    div {
      margin: 10px;
    }
    
    p {
      padding: 2px;
      margin: 0px;
    }
    <div id="data">
      <div id="splitter">
        <div id="left-content">
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
        </div>
        <div id="right-content">
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>          
        </div>
      </div>
    </div>
    Login or Signup to reply.
  2. Maybe something like this helps, if you try to run the code snippet below;

    <html>
    <style>
    #data {
      background: grey;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      
      height: 400px;
      width: 500px;
    }
    
    #splitter {
      display: flex;
      flex-direction: row;
      background: darkgrey;
      overflow-x: hidden;
      overflow-y: auto;
      align-items:start;
    }
    
    #right-content {
      background: Gainsboro;
      overflow: scroll;
    }
    
    #left-content {
      background: Gainsboro;
      overflow: scroll;
    }
    
    div {
      margin: 10px;
    }
    
    p {
      padding: 2px;
      margin: 2px;
    }
    </style>
    
    <body>
    <div id="data">
      <div id="splitter">
        <div class="myDiv" id="left-content">
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
          <p>LeftColumnLeftColumn</p>
        </div>
        <div class="myDiv" id="right-content">
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>
          <p>RightColumnWithLongTextThatShouldBeScrollableHorizontally</p>          
        </div>
      </div>
    </div>
      <script type="text/javascript">
        const divs = document.querySelectorAll('.myDiv');;
    
        divs.forEach(div => div.addEventListener( 'scroll', e => {
      
        const offsetTop = div.scrollTop / (div.scrollHeight - div.clientHeight);
      
        const offsetLeft = div.scrollLeft / (div.scrollWidth - div.clientWidth);
      
        divs.forEach(d => {
      
                d.scrollTop = offsetTop * (d.scrollHeight - d.clientHeight);
                d.scrollLeft = offsetLeft * (d.scrollWidth - d.clientWidth);
        
        });
      
        }) );
      </script>
    
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search