JSFiddle - React, Tailwind, and code Playground
Responsive Table
by Jennifer Perrin
HTML
<table>
<thead>
<tr>
<th>#</th>
<th>Client ID</th>
<th>Name</th>
<th>Project Title</th>
<th>Status</th>
<th>Fee</th>
<th>Payments Completed</th>
<th>Notes</th>
<th>Start Date</th>
<th>Due Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>John Smith</td>
<td>Static HTML Site</td>
<td>New</td>
<td>500.00</td>
<td>1</td>
<td>Some Project Notes. Some Project Notes. Some Project Notes. Some Project Notes.</td>
<td>2013-01-01</td>
<td>2013-06-30</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>John Smith</td>
<td>WordPress Install</td>
<td>New</td>
<td>250.00</td>
<td>0</td>
<td></td>
<td>2013-01-01</td>
<td>2013-06-30</td>
</tr>
</tbody>
</table>
CSS
@import url(http://fonts.googleapis.com/css?family=Raleway);
body { font-family: 'Raleway'; }
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(odd) {
background: #eee;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}
th {
background: #333;
color: white;
font-size: 14px;
font-weight: normal;
}
td {
font-size: 13px;
}
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr { border: 1px solid #ccc; }
td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
td:nth-of-type(1):before { content: "#"; font-weight: bold; }
td:nth-of-type(2):before { content: "Client ID:"; font-weight: bold; }
td:nth-of-type(3):before { content: "Name:"; font-weight: bold; }
td:nth-of-type(4):before { content: "Project Title:"; font-weight: bold; }
td:nth-of-type(5):before { content: "Status:"; font-weight: bold; }
td:nth-of-type(6):before { content: "Fee:"; font-weight: bold; }
td:nth-of-type(7):before { content: "Payments Completed:"; font-weight: bold; }
td:nth-of-type(8):before { content: "Notes:"; font-weight: bold; }
td:nth-of-type(9):before { content: "Start Date:"; font-weight: bold; }
td:nth-of-type(10):before { content: "Due Date:"; font-weight: bold; }
}
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
...