Skip to content

Commit

Permalink
feat: responsive table & set its width to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Feb 24, 2020
1 parent 1cc02c3 commit a995897
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
15 changes: 15 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
wrapTable();

function wrapTable() {
const tables = document.querySelectorAll('div.post-body table');

for (let i = 0; i < tables.length; i++) {
const parent = tables[i].parentNode;
const wrapper = document.createElement('div');

wrapper.className = 'table-container';

parent.replaceChild(wrapper, tables[i]);
wrapper.appendChild(tables[i]);
}
}
8 changes: 5 additions & 3 deletions assets/scss/layout/_single.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ ol.toc {
}
}

.table-container {
margin: 2em 0;
overflow-x: auto;
}
table {
display: block;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
border-color: var(--color-contrast-lower);
margin: 2em 0;
overflow-x: auto;
}
th {
font-weight: 700;
Expand Down
Loading

0 comments on commit a995897

Please sign in to comment.