Skip to content

Instantly share code, notes, and snippets.

@davdenic
Created October 12, 2018 08:17
Show Gist options
  • Save davdenic/c5911086a6e1bdaee7093d997303e224 to your computer and use it in GitHub Desktop.
Save davdenic/c5911086a6e1bdaee7093d997303e224 to your computer and use it in GitHub Desktop.
responsive tables pure CSS... well SASS
/* tables responsive for smartphones */
@media only screen and (max-width: $screen-xs-max) {
//Force table to not be like tables anymore
table.table-responsive,
table.table-responsive-labels {
display: block;
thead, tbody, th, td {
display: block;
border: none !important;
vertical-align: top !important;
}
//Hide table headers (but not display: none;, for accessibility)
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
//Tr become blocks
tr {
display: block;
border-top: 0 !important;
border-left: 0 !important;
border-right: 0 !important;
border-bottom: $grid-gutter-width/2 solid #fff !important;
padding: $grid-gutter-width/2 !important;
}
//td become lines
td {
display: inline;
padding: 0 !important;
}
}
//tables with labels passed as data-label attribute in html code
table.table-responsive-labels {
td {
//Behave like a "row"
display: block;
position: relative;
padding-left: 50% !important;
}
td:before {
// add data-label as label
content: attr(data-label);
position: absolute;
top: 0;
left: 0;
width: 45%;
white-space: nowrap;
overflow-x: hidden;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment