Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>HTML Table Freeze Column and Row like Ms. Excel</h1>
<p>Fixed col header and row on scroll left and right.<br/>
Original post: <strong>https://www.igniel.com/2022/02/table-sticky-header-kolom-baris.html</strong></p>

<div class="inner">

<div class="table-freeze">
  <table>
    <thead>
      <tr>
        <th class="tp" scope="col"></th>
        <th scope="col">Satu</th>
        <th scope="col">Dua</th>
        <th scope="col">Tiga</th>
        <th scope="col">Empat</th>
        <th scope="col">Lima</th>
        <th scope="col">Enam</th>
        <th scope="col">Tujuh</th>
        <th scope="col">Delapan</th>
        <th scope="col">Sembilan</th>
        <th scope="col">Sepuluh</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Klub 1</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 2</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 3</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 4</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 5</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 6</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 7</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 8</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 9</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
      <tr>
        <th scope="row">Klub 10</th>
        <td scope="row">Satu</td>
        <td scope="row">Dua</td>
        <td scope="row">Tiga</td>
        <td scope="row">Empat</td>
        <td scope="row">Lima</td>
        <td scope="row" >Enam</td>
        <td scope="row">Tujuh</td>
        <td scope="row">Delapan</td>
        <td scope="row">Sembilan</td>
        <td scope="row">Sepuluh</td>
      </tr>
    </tbody>
  </table>
</div>
  
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
  <p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
  <p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  
</div>
              
            
!

CSS

              
                body {
  background-color: #fff;
  font: 400 14px system-ui, -apple-system, BlinkMacSystemFont, 'Ubuntu', 'Segoe UI', 'Oxygen-Sans', 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.5rem;
  margin: 2rem;
}
h1 {
  line-height: 2.25rem;
  margin-bottom: 0;
}
p {
  margin: .5rem 0 2rem;
}
.inner {
  max-width: 860px;
}

/*--- TABLE ---*/
.table-freeze {
  height: 80vh;
  margin: 2rem 0;
  overflow: auto;
  scroll-snap-type: both mandatory;
  white-space: nowrap;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}
th, td {
  padding: 1rem 2.5rem;
  text-align: left;
}
thead th {
  border-bottom: 1px solid #ccc;
  font-weight: 600;
  top: 0;
  z-index: 1;
}
th.tp {
  background-color: #fff;
  z-index: 2;
}
tbody th {
  left: 0;
  text-align: left;
}
tbody th, th.tp {
  border-right: 1px solid #ccc;
}
tr {
  padding: 0;
}
td {
  color: #555;
  vertical-align: top;
}
tbody tr:nth-child(odd) th {
  background-color: #fff;
}
thead th, tbody tr:nth-child(even) th, tr:nth-child(even) td {
  background-color: #f4f4f4; /* striped background color */
}
thead th, tbody th {
  position: sticky;
  -webkit-position: sticky;
}
@media screen and (max-width: 680px) {
  .table-freeze{height:70vh}
}
@media screen and (max-width: 480px) {
  .table-freeze{height:60vh}
}
              
            
!

JS

              
                
              
            
!
999px

Console