[html] Table with fixed header and fixed column on pure css

Nowadays, this is possible to achieve using CSS only with position: sticky property.

Here goes a snippet:

(jsFiddle: https://jsfiddle.net/hbqzdzdt/5/)

_x000D_
_x000D_
.grid-container {_x000D_
  display: grid; /* This is a (hacky) way to make the .grid element size to fit its content */_x000D_
  overflow: auto;_x000D_
  height: 300px;_x000D_
  width: 600px;_x000D_
}_x000D_
.grid {_x000D_
  display: flex;_x000D_
  flex-wrap: nowrap;_x000D_
}_x000D_
.grid-col {_x000D_
  width: 150px;_x000D_
  min-width: 150px;_x000D_
}_x000D_
_x000D_
.grid-item--header {_x000D_
  height: 100px;_x000D_
  min-height: 100px;_x000D_
  position: sticky;_x000D_
  position: -webkit-sticky;_x000D_
  background: white;_x000D_
  top: 0;_x000D_
}_x000D_
_x000D_
.grid-col--fixed-left {_x000D_
  position: sticky;_x000D_
  left: 0;_x000D_
  z-index: 9998;_x000D_
  background: white;_x000D_
}_x000D_
.grid-col--fixed-right {_x000D_
  position: sticky;_x000D_
  right: 0;_x000D_
  z-index: 9998;_x000D_
  background: white;_x000D_
}_x000D_
_x000D_
.grid-item {_x000D_
  height: 50px;_x000D_
  border: 1px solid gray;_x000D_
}
_x000D_
<div class="grid-container">_x000D_
  <div class="grid">_x000D_
    <div class="grid-col grid-col--fixed-left">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>Hello</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>P</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
    <div class="grid-col grid-col--fixed-right">_x000D_
      <div class="grid-item grid-item--header">_x000D_
        <p>HEAD</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
      <div class="grid-item">_x000D_
        <p>9</p>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
  </div>_x000D_
</div>
_x000D_
_x000D_
_x000D_

Regarding compatibility. It works in all major browsers, but not in IE. There is a polyfill for position: sticky but I never tried it.

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to html-table

Table column sizing DataTables: Cannot read property 'length' of undefined TypeError: a bytes-like object is required, not 'str' in python and CSV How to get the <td> in HTML tables to fit content, and let a specific <td> fill in the rest How to stick table header(thead) on top while scrolling down the table rows with fixed header(navbar) in bootstrap 3? Sorting table rows according to table header column using javascript or jquery How to make background of table cell transparent How to auto adjust table td width from the content bootstrap responsive table content wrapping How to print table using Javascript?

Examples related to markup

Table with fixed header and fixed column on pure css href overrides ng-click in Angular.js Section vs Article HTML5 Vertical dividers on horizontal UL menu How do I add space between items in an ASP.NET RadioButtonList How to mark-up phone numbers? How to make PDF file downloadable in HTML link? Is there a way to comment out markup in an .ASPX page?

Examples related to fixed-header-tables

Table with fixed header and fixed column on pure css