Skip to content

Instantly share code, notes, and snippets.

@fieke
Created November 12, 2013 15:13
Show Gist options
  • Save fieke/7432497 to your computer and use it in GitHub Desktop.
Save fieke/7432497 to your computer and use it in GitHub Desktop.
responsive tables
(function($) {
$('thead').each(function() {
$th = $(this).find('th')
$(this).next('tbody').find('tr').each(function(tr) {
for(var i = 0; i < $th.length; i++) {
$(this).find('th, td').eq(i).attr('data-label', $th.eq(i).text());
}
});
});
})(jQuery);
table {
border: 0px solid #ccc;
width: 100%;
}
thead {
display: none;
}
thead, tbody {
float: left;
width: 100%;
}
td, th {
display: block;
width: 100%;
height: 30px;
text-align: center;
border: 1px solid #ddd;
border-bottom: 0px;
/*width: 100%;*/
float: left;
clear: both;
}
td:before {
content: attr(data-label) ": ";
}
tr {
width: 100%;
display: block;
float: left;
margin-bottom: 20px;
border-bottom: 1px solid #ddd;
}
@media screen and (min-width: 526px) {
table {
width: auto;
}
thead, tbody {
width: auto;
display: block;
}
tr {
width: 100px;
}
td, th {
width: 100px;
clear: both;
}
td:before {
content: "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment