public
Last active

Responsive Tables

  • Download Gist
index.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Responsive Tables</title>
<!-- viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link rel="stylesheet" href="style.css" type="text/css">
<!-- JS -->
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="css3-mediaqueries.js"></script>
<script type="text/javascript" src="html5.js"></script>
<!-- REPLACE TABLE JQUERY -->
<script type="text/javascript">
jQuery(document).ready(function() {
// REPLACE TABLE
$('table').replaceWith(function(){
return $("<div class='tablearea_table'/>").append($(this).contents());
});
// REPLACE TD
$('td').contents().unwrap().wrap('<div class="tablearea_cell"><div class="tablearea_cellitem">');
// REPLACE TH
$('th').contents().unwrap().wrap('<div class="tablearea_header"><div class="tablearea_cellitem">');
// REPLACE TR
$('tr').replaceWith(function(){
return $("<div class='tablearea_row'/>").append($(this).contents());
});
// REPLACE THEAD
$('thead').replaceWith(function(){
return $("<div class='tablearea_headerrow'/>").append($(this).contents());
});
// REPLACE TBODY
$('tbody').replaceWith(function(){
return $("<div class='tablearea_tbodyrow'/>").append($(this).contents());
});
// Odd and Even Classes
$('div.tablearea_row:nth-child(even)').addClass('odd_rows');//Rows
$('div.tablearea_cell:nth-child(even)').addClass('odd_columns');//Columns
// First Column TD
$('.tablearea_row .tablearea_cell:first-child').addClass('first');
});
</script>
</head>
 
<body>
<table>
<thead>
<tr>
<th>&nbsp;</th>
<th>IE</th>
<th>Firefox</th>
<th>Chrome</th>
<th>Safari</th>
<th>Opera</th>
<th>iOS Safari</th>
<th>Android Browser</th>
</tr>
</thead>
<tr>
<td>CSS 3</td>
<td>:p</td>
<td>:)</td>
<td>:)</td>
<td>:)</td>
<td>:)</td>
<td>:)</td>
<td>:)</td>
</tr>
<tr>
<td>Fun to use</td>
<td>:p</td>
<td>:)</td>
<td>:)</td>
<td>:)</td>
<td>:(</td>
<td>:)</td>
<td>:P</td>
</tr>
</table>
</body>
</html>
style.css
CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/* ======================================================================================================= */
/* RESET */
/* ======================================================================================================= */
 
:link,:visited {text-decoration:none;}
ul,ol {list-style:none;}
h1,h2,h3,h4,h5,h6,pre,code {font-size:small;}
ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input, legend {margin:0;padding:0;}
a img,:link img,:visited img {border:none;}
address {font-style:normal;}
fieldset {border:none;}
 
* {margin:0px;padding:0px;outline:none;}
 
html {
margin:0px;padding:0px;
font-size:100.01%;
width:100%;height:100%;
}
 
body {
margin:0px;padding:0px;
background-color:#fff;
font:14px/20px Verdana, Arial, Helvetica, sans-serif;color:#666;
}
 
 
 
 
 
/* ======================================================================================================= */
/* Generic Styling, for Desktops/Laptops */
/* ======================================================================================================= */
 
table {
width: 100%;
border-collapse: collapse;
}
 
/* =============== Zebra striping =============== */
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}
.first {color:#000;font-weight:bold;}
 
 
/* ======================================================================================================= */
/* TABLE REPLACE */
/* ======================================================================================================= */
 
 
.tablearea_table { /* TABLE */
display:block;overflow:hidden;clear:both;
width:100%;height:100%;
}
 
.tablearea_headerrow{ /* thead */
display:block;overflow:hidden;clear:both;
width:100%;
font-weight:bold;
}
.tablearea_tbodyrow{ /* tbody */
display:block;overflow:hidden;clear:both;
width:100%;
color:#35505f;
}
.tablearea_row{ /* tr */
display:block;overflow:hidden;clear:both;
padding:0px;
width:100%;height:4em;
}
.tablearea_header { /* th */
display:block;overflow:hidden;
float:left;
padding:0px;
text-align:center;
width:12%;height:4em;
background:#999 url(1.gif) right top repeat-y;
}
.tablearea_cell { /* td */
display:block;overflow:hidden;
float:left;
padding:0px;
text-align:center;
width:12%;height:4em;
background:url(1.gif) right top repeat-y;
}
.tablearea_cellitem {padding:2px 4px;}
 
.tablearea_row.odd_rows .tablearea_cell {background-color:#ccc;display:block;overflow:hidden;}
.tablearea_cell.odd_columns {/* Go Nutz */}
@media only screen and (max-width: 760px) {
 
 
.tablearea_headerrow{ /* thead */
display:block;overflow:hidden;clear:both;
width:100%;
font-weight:bold;
}
.tablearea_tbodyrow{ /* tbody */
display:block;overflow:hidden;clear:both;
width:100%;
color:#35505f;
}
.tablearea_row{ /* tr */
display:block;overflow:hidden;clear:both;
padding:0px;
width:100%;height:auto;
}
.tablearea_header {display:none;} /* th */
.tablearea_cell { /* td */
display:block;overflow:hidden;
padding-left:50%;
width:100%;height:auto;
background:none;
position:relative;
text-align:left;
}
.tablearea_cell:before {
position:absolute;top:6px;left:6px;
width:45%;
padding-right:10px;
white-space:nowrap;
}
.tablearea_cellitem {padding:2px 4px;}
 
.tablearea_row.odd_rows .tablearea_cell {background-color:#ccc;display:block;overflow:hidden;}
.tablearea_cell.odd_columns {/* Go Nutz */}
/* =============== Label the data =============== */
.tablearea_cell:nth-of-type(2):before { content: "IE"; }
.tablearea_cell:nth-of-type(3):before { content: "Firefox"; }
.tablearea_cell:nth-of-type(4):before { content: "Chrome"; }
.tablearea_cell:nth-of-type(5):before { content: "Safari"; }
.tablearea_cell:nth-of-type(6):before { content: "Opera"; }
.tablearea_cell:nth-of-type(7):before { content: "iOS Safari"; }
.tablearea_cell:nth-of-type(8):before { content: "Android Browser"; }
 
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.