Skip to content

Instantly share code, notes, and snippets.

@troutacular
Created April 6, 2016 23:29
Show Gist options
  • Save troutacular/b931e3fea6fa9aa6bbb5ba8d2554b8db to your computer and use it in GitHub Desktop.
Save troutacular/b931e3fea6fa9aa6bbb5ba8d2554b8db to your computer and use it in GitHub Desktop.
CSS Responsive Table
table {
/* remove if moving header */
display: block;
overflow: auto;
/* end */
margin: 0 0 1.5em;
width: 100%;
background-color: #fff;
border: 1px solid #000;
border-bottom: none;
}
thead {
tr {
background-color: #fff;
}
}
th {
font-weight: bold;
line-height: 1;
}
tbody {
tr{
&:nth-child(odd){
background-color: #ccc;
}
}
}
tr {}
td {}
th,td {
border-bottom: 1px solid #000;
border-collapse: collapse;
padding: 1em;
}
/* responsive with headers on the left */
@media only screen and (max-width: 40em){
table {
display: block;
position: relative;
}
thead {
display: block;
float: left;
width: 30%;
tr {
display: block;
}
}
th {
display: block;
min-height: 6rem;
word-wrap: break-word;
word-break: hyphenate;
}
tbody {
display: block;
width: auto;
position: relative;
overflow-x: auto;
white-space: nowrap;
tr {
display: inline-block;
vertical-align: top;
}
}
td {
display: block;
min-height: 6rem;
width: auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment