Skip to content

Instantly share code, notes, and snippets.

@RemeJuan
Created April 4, 2016 06:31
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 RemeJuan/762ada2051bdc6269284b81ba6cb19f0 to your computer and use it in GitHub Desktop.
Save RemeJuan/762ada2051bdc6269284b81ba6cb19f0 to your computer and use it in GitHub Desktop.
Better responsive table
@media only screen and (max-width: 800px) {
.enhanced-responsive-table {
table, thead, tbody, th, td, tr {
display: block;
}
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr {
border: 1px solid #ccc;
}
td {
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
white-space: normal;
text-align:left;
}
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;
text-align:left;
font-weight: bold;
}
td:before {
content: attr(data-title);
}
}
}
<div class="enhanced-responsive-table">
<table class="col-md-12 table-bordered table-striped table-condensed cf">
<thead class="cf">
<tr>
<th class="col-md-4">Head 1</th>
<th class="col-md-4">Head 2</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Head 1">Column</td>
<td data-title="Head 2">Column</td>
</tr>
</tbody>
</table>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment