Skip to content

Commit cb9bb53

Browse files
authored
Fix table overlapping and improve responsiveness #688 (#1222)
Fix #688
1 parent 746540a commit cb9bb53

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

js/common.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,24 @@ function getLanguage() {
819819
$link.attr('href', $link.attr('href') + window.location.hash);
820820
});
821821
})(jQuery);
822+
823+
(function ($) {
824+
/**
825+
* Each th will dynamically set for the corresponding td the attribute of
826+
* "data-label" with the text of the th.
827+
*/
828+
$(document).ready(function () {
829+
$('table').each(function () {
830+
var $table = $(this);
831+
$table.find('th').each(function (index) {
832+
var $th = $(this);
833+
var text = $th.text();
834+
if (text === '') {
835+
return;
836+
}
837+
$table.find('td:nth-child(' + (index + 1) + ')')
838+
.attr('data-label', text);
839+
});
840+
});
841+
});
842+
})(jQuery);

styles/theme-base.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,3 +1632,55 @@ aside.tips div.inner {
16321632
.caption {
16331633
font-size: 0.85rem;
16341634
}
1635+
1636+
/**
1637+
* Table overlapping fix
1638+
*/
1639+
.table {
1640+
width: 100%;
1641+
margin: 1% !important;
1642+
border-spacing: 20px;
1643+
table-layout: fixed;
1644+
}
1645+
1646+
td {
1647+
word-wrap: break-word;
1648+
}
1649+
1650+
@media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {
1651+
/* Make table elements block for stacking */
1652+
table, thead, tbody, th, td, tr {
1653+
display: block;
1654+
}
1655+
1656+
/* Hide the table headers */
1657+
thead tr {
1658+
position: absolute;
1659+
top: -9999px;
1660+
left: -9999px;
1661+
}
1662+
1663+
tr {
1664+
margin: 0 0 1rem 0;
1665+
}
1666+
1667+
td {
1668+
border: none;
1669+
border-bottom: 1px solid #eee;
1670+
position: relative;
1671+
}
1672+
td:before {
1673+
left: -.50rem;
1674+
top: -0.3rem;
1675+
padding: .25rem .5rem;
1676+
width: 100%;
1677+
font-weight: bold;
1678+
border: none;
1679+
background-color: #C4C9DF;
1680+
border-bottom: 1px solid #eee;
1681+
position: relative;
1682+
display: block;
1683+
unicode-bidi: isolate;
1684+
content: attr(data-label);
1685+
}
1686+
}

0 commit comments

Comments
 (0)