-
  const rand = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  const makeRandomScores = () => {
    let scoreArray = [];
    for (let inning = 1; inning < 10; inning++) {
      scoreArray.push(rand(0, 4));
    }
    scoreArray.push(scoreArray.reduce((a, b) => a + b, 0));
    return scoreArray;
  }

  const teams = [
    { "name": "Milwaukee Brewers", scores: makeRandomScores() },
    { "name": "Los Angles Dodgers", scores: makeRandomScores() },
    { "name": "New York Mets", scores: makeRandomScores() },
    { "name": "St. Louis Cardinals", scores: makeRandomScores() },
    { "name": "Houston Astros", scores: makeRandomScores() },
    { "name": "Toronto Blue Jays", scores: makeRandomScores() },
    { "name": "Boston Red Sox", scores: makeRandomScores() },
    { "name": "Chicago Cubs", scores: makeRandomScores() },
    { "name": "Philadelphia Phillies", scores: makeRandomScores() },
    { "name": "Chicago White Sox", scores: makeRandomScores() },
    { "name": "San Diego Padres", scores: makeRandomScores() },
    { "name": "Cleveland Indians", scores: makeRandomScores() },
    { "name": "San Francisco Giants", scores: makeRandomScores() },
    { "name": "Cincinatti Reds", scores: makeRandomScores() },
    { "name": "Minnesota Twins", scores: makeRandomScores() },
    { "name": "Tampa Bay Rays", scores: makeRandomScores() },
    { "name": "Miami Marlins", scores: makeRandomScores() },
    { "name": "Oakland Athletics", scores: makeRandomScores() },
    { "name": "Detroit Tigers", scores: makeRandomScores() },
    { "name": "Pittsburgh Pirates", scores: makeRandomScores() },
    { "name": "Seattle Mariners", scores: makeRandomScores() },
    { "name": "Atlanta Braves", scores: makeRandomScores() }
  ];

div(role="region", aria-labelledby="caption", tabindex="0")
  table
    caption#caption Baseball numbers mmkay.
    thead
      tr
        th Teams
        each val in [1, 2, 3, 4, 5, 6, 7, 8, 9]
          th= val
        th Runs
    tfoot
      tr
        th Teams
        each val in [1, 2, 3, 4, 5, 6, 7, 8, 9]
          th= val
        th Runs
    tbody
      each team in teams
        tr
          th= team.name
          each score in team.scores
            td= score
View Compiled
@import url("https://fonts.googleapis.com/css2?family=Fraunces:ital,wght@0,700;1,200&display=swap");

table {
  font-family: "Fraunces", serif;
  font-size: 125%;
  white-space: nowrap;
  margin: 0;
  border: none;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  border: 1px solid black;
}
table td,
table th {
  border: 1px solid black;
  padding: 0.5rem 1rem;
}
table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}
table tfoot {
  position: sticky;
  bottom: 0;
  z-index: 1;
}
table thead th,
table tfoot th {
  padding: 3px;
  width: 25vw;
  background: lightyellow;
}
table td {
  background: #fff;
  padding: 4px 5px;
  text-align: center;
}

table tbody th {
  font-weight: 100;
  font-style: italic;
  text-align: left;
  position: relative;
}
table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: lightyellow;
}
table thead th:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  background: lightyellow;
}

table tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: lightyellow;
}
table tbody td:last-child {
  position: sticky;
  right: 0;
  background: lightyellow;
  z-index: 1;
}
caption {
  text-align: left;
  padding: 0.25rem;
  position: sticky;
  left: 0;
}

[role="region"][aria-labelledby][tabindex] {
  width: 100%;
  max-height: 98vh;
  overflow: auto;
}
[role="region"][aria-labelledby][tabindex]:focus {
  box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.5);
  outline: 0;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/jquery-throttle-debounce/1.1/jquery.ba-throttle-debounce.min.js