Skip to content

Instantly share code, notes, and snippets.

@andberry
Created September 30, 2021 01:58
Show Gist options
  • Save andberry/1406535e20d5a02248d1d22608949d22 to your computer and use it in GitHub Desktop.
Save andberry/1406535e20d5a02248d1d22608949d22 to your computer and use it in GitHub Desktop.
Responsive Tables: quick solution to make a table horizontally scrollable
/*
responsiveTables.js
add a wrapper around every table in DOM
and style make it horizontally scrollable (css below)
*/
function responsiveTables() {
const tablesEls = document.querySelectorAll('table');
for (const item of Array.from(tablesEls)) {
const tableWrapperEl = document.createElement('div');
tableWrapperEl.classList.add('c-responsive-table-wrapper');
item.parentNode.insertBefore(tableWrapperEl, item);
tableWrapperEl.appendChild(item);
}
}
/*
_responsive-table-wrapper.scss
*/
.c-responsive-table-wrapper {
overflow-x: scroll;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment