RWD Responsive Table
Table switching to accordion on small screensizes.
http://jsfiddle.net/Freizeitler/fzJLZ/
HTML
<div class="content-box">
<table>
<tr>
<td>Testkurs </td>
<td>Am Ort</td>
<td>Kurze Beschreibung</td>
<td>Uhrzeit</td>
<td>Uhrzeit (MItteleuropäisch)</td>
</tr>
<tr>
<td>Beispielkurs</td>
<td>Platz</td>
<td>Folgende Inhalte</td>
<td>Zeitpunkt</td>
<td>Zeitpunkt (in Worten)</td>
</tr>
</table>
</div>
CSS
table {
background: none;
margin-bottom: 1.25em;
border: none;
}
table thead, table tfoot {
font-weight: bold;
}
table thead tr th, table thead tr td, table tfoot tr th, table tfoot tr td {
padding: 0.5em 0.625em 0.625em;
font-size: 1.125em;
color: #818181;
text-align: left;
}
table tr th, table tr td {
padding: 1.25em 0.625em;
font-size: 1.125em;
color: #6e6e6e;
}
table thead tr th {
text-transform: uppercase;
}
table tr {
border-bottom: 10px solid #E9E9E9;
}
table tbody tr {
background: #f9f9f9;
}
table tbody tr:first-child {
background: none;
border-bottom: none;
}
table tbody th {
text-align: left;
font-weight: bold;
}
table thead tr th, table tfoot tr th, table tbody tr td, table tr td, table tfoot tr td {
display: table-cell;
line-height: 1.125em;
}
table, th, tr:first-child td {
font: normal 19px/1.4 sans-serif;
color: #6e6e6e;
font-size: 15px;
}
th, tr:first-child td {
font-weight: bold;
}
.icon-accordion {
display: none;
}
.content-box td h3 {
margin: 0;
padding: 0 0 5px 0;
display: none;
font-weight: bold;
}
@media (max-width: 764px) {
.content-box table, .content-box tbody, .content-box tr, .content-box td, .content-box th {
display: block;
width: 100%;
}
.content-box tr {
max-height: 60px;
overflow: hidden;
position: relative;
cursor: pointer;
}
.content-box td:first-child {
color: #ee8025;
}
.content-box tr:first-child td:first-child {
color: #6e6e6e;
}
.icon-accordion {
display: block;
color: #ee8025;
text-align: center;
width: 16px;
height: 16px;
position: absolute;
right: 15px;
top: 15px;
font-style: normal;
font-size: 1.6em;
}
.content-box td h3 {
display: block;
}
}
JavaScript
// table to accordion
$(function () {
$("table").each(function () {
var trAcc = $(this).find("tr").not("tr:first-child, tr:first-child th"),
thRows = trAcc.length,
thHead = [];
$(this).find("tr:first-child td, tr:first-child th").each(function () {
headLines = $(this).text();
thHead.push(headLines);
});
trAcc.each(function () {
for (i = 0, l = thHead.length; i < l; i++) {
$(this).find("td").eq(i + 1).prepend("<h3>" + thHead[i + 1] + "</h3>");
}
});
trAcc.append('<i class="icon-accordion">+</i>');
trAcc.click(function () {
if ($(this).hasClass("accordion-opened")) {
$(this).animate({
maxHeight: "60px"
}, 200).removeClass("accordion-opened").find(".icon-accordion").text("+");
} else {
$(this).animate({
maxHeight: "1000px"
}, 400).addClass("accordion-opened").find(".icon-accordion").text("-");
}
});
});
});