Created
February 18, 2015 19:27
-
-
Save aheissenberger/118e6c85ea2e48123598 to your computer and use it in GitHub Desktop.
HTML Table responsive - flip Tableheader to first column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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