Created
September 30, 2021 01:58
-
-
Save andberry/1406535e20d5a02248d1d22608949d22 to your computer and use it in GitHub Desktop.
Responsive Tables: quick solution to make a table horizontally scrollable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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