title: Responsive horizontal scrolling table with fixed columns
body: <p>I'd like to create a table that has two fixed columns, left and right and a horizontally scrollable section in the middle. An issue is that because the table is responsive, a width value can't be provided for the overflow and there could be any number of columns or rows.</p>
  
  <p>See the mockup here - the middle section scrolls but the two columns on the left and right stay fixed.</p>
  
  <p><a href="https://i.stack.imgur.com/hyQgX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hyQgX.png" alt="enter image description here"></a></p>
  
  <p>I've already tried this by floating three different tables together but this is messy and very hard to maintain.</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          ...
      &lt;/thead&gt;
      &lt;tbody&gt;
          ...
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;div class="scrollable-section"&gt;
      &lt;table&gt;
          &lt;thead&gt;
              ...
          &lt;/thead&gt;
          &lt;tbody&gt;
              ...
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;table&gt;
      &lt;thead&gt;
          ...
      &lt;/thead&gt;
      &lt;tbody&gt;
          ...
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Basically, I'd like to achieve this inside one table and I don't mind any added bits of JavaScript if neccessary using this markup:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>table {
    position: relative;
    width: calc(100% - 200px);
    margin-left: 100px;
  }
  
  table {
    overflow-x: scroll;
  }
  
  table th {
    background: #333;
    color: #fff;
    padding: 12px;
  }
  
  table td:first-of-type, table th:first-of-type {
  /* fixed left column */
    position: absolute;
    left: -100px;
    width: 100px;
    
  }
  
  table td:last-of-type, table th:last-of-type {
  /* fixed right column */
    position: absolute;
    right: -100px;
    width: 100px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Row titles&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Row title&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;&lt;button&gt;Do something&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Row title&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;...&lt;/td&gt;
              &lt;td&gt;&lt;button&gt;Do something&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>