Created
November 12, 2013 15:13
-
-
Save fieke/7432497 to your computer and use it in GitHub Desktop.
responsive tables
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
(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); |
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
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