Skip to content

Instantly share code, notes, and snippets.

@thm-design
Created March 27, 2013 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thm-design/5253147 to your computer and use it in GitHub Desktop.
Save thm-design/5253147 to your computer and use it in GitHub Desktop.
A CodePen by Josh Rives. Simple Responsive Table - Resize your browser below 700px to view. This is a simple responsive table. The shadows on the sides are just to indicate that the user should slide to see the rest on mobile. You could easily make the shadow appear and disappear depending on if you at either end with jquery scrollLeft.
<section>
<div>
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Number</th>
<th>City</th>
<th>Team</th>
<th>Position</th>
<th>Sport</th>
<th>College</th>
<th>Age</th>
<th>Active</th>
</tr>
</thead>
<tbody>
<tr>
<td>Demarcus</td>
<td>Ware</td>
<td>94</td>
<td>Dallas</td>
<td>Cowboys</td>
<td>OLB</td>
<td>Football</td>
<td>Troy</td>
<td>30</td>
<td>Yes</td>
</tr>
<tr>
<td>Tony</td>
<td>Romo</td>
<td>9</td>
<td>Dallas</td>
<td>Cowboys</td>
<td>QB</td>
<td>Football</td>
<td>Eastern Illinois</td>
<td>32</td>
<td>Yes</td>
</tr>
<tr>
<td>Jason</td>
<td>Witten</td>
<td>82</td>
<td>Dallas</td>
<td>Cowboys</td>
<td>TE</td>
<td>Football</td>
<td>Tennessee</td>
<td>30</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
</section>
@import "compass";
section {
width: 80%;
margin: 0 auto;
position: relative;
border-right: 2px dashed #ddd;
border-left: 2px dashed #ddd;
}
table {
width: 100%;
text-align: center;
min-width: 700px;
}
th, td {
width: 10%;
padding: 10px 0;
}
th {
color: #002E4D;
}
tr {
border-top: 4px solid #fff;
background: #F1F1F0;
&:nth-child(even) {
background: #f9f9f9;
}
thead &{
background: #aaa;
}
}
div {
overflow-x:scroll;
}
@media only screen
and (max-width : 700px) {
section:after {
content:'';
position: absolute;
z-index: 10;
top: 0;
bottom: 0;
right: 0;
width: 10%;
background: -webkit-linear-gradient(left, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -moz-linear-gradient(left, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -ms-linear-gradient(left, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -o-linear-gradient(left, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: linear-gradient(to right, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
}
section:before {
content:'';
position: absolute;
z-index: 10;
top: 0;
bottom: 0;
left: 0;
width: 10%;
background: -webkit-linear-gradient(right, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -moz-linear-gradient(right, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -ms-linear-gradient(right, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: -o-linear-gradient(right, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
background: linear-gradient(to left, rgba(0,0,0,0) 10%, rgba(0,0,0,0.2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment