Skip to content

Instantly share code, notes, and snippets.

@aheissenberger
Created February 18, 2015 19:27
Show Gist options
  • Save aheissenberger/118e6c85ea2e48123598 to your computer and use it in GitHub Desktop.
Save aheissenberger/118e6c85ea2e48123598 to your computer and use it in GitHub Desktop.
HTML Table responsive - flip Tableheader to first column
<style>
@media screen and (max-width: 600px) {
table.responsive caption { background-image: none; }
table.responsive thead { display: none; }
table.responsive tbody td { display: block; padding: .6rem; }
table.responsive tbody tr td:first-child { background: #333; color: #fff; }
table.responsive tbody td:before {
content: attr(data-th); font-weight: bold;
display: inline-block; width: 6rem;
}
}
</style>
<script>
$('table.responsive').each(function(){
var headers = $( 'thead th',this );
$( 'tbody tr',this ).each(function(){
$( 'td',this ).each(function(index){
$( this ).attr('data-th',$(headers[index]).text());
});
});
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment