Skip to content

Instantly share code, notes, and snippets.

@Fuzzwah
Created February 4, 2023 00:24
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 Fuzzwah/4de98322f5003964f97d7915a7ea19a2 to your computer and use it in GitHub Desktop.
Save Fuzzwah/4de98322f5003964f97d7915a7ea19a2 to your computer and use it in GitHub Desktop.
Responsive Table (with Bootstrap)
<table class="table table-xs-responsive table-hover" summary="An example of a responsive table using Bootstrap breakpoints." aria-role="table">
<h1 class="text-center">Responsive Table</h1>
<caption class="text-center">Rather than using the overflow feature of the built in Bootstrap <code>.table-responsive</code>, this option will stack each cell at the set breakpoint.</caption>
<thead>
<tr>
<th>Entry Header 1</th>
<th>Entry Header 2</th>
<th>Entry Header 3</th>
<th>Entry Header 4</th>
</tr>
</thead>
<tbody>
<tr class="success">
<td>Entry First Line 1</td>
<td>Entry First Line 2</td>
<td>Entry First Line 3</td>
<td>Entry First Line 4</td>
</tr>
<tr class="info">
<td>Entry Line 1</td>
<td>Entry Line 2</td>
<td>Entry Line 3</td>
<td>Entry Line 4</td>
</tr>
<tr class="warning">
<td>Entry Last Line 1</td>
<td>Entry Last Line 2</td>
<td>Entry Last Line 3</td>
<td>Entry Last Line 4</td>
</tr>
</tbody>
</table>
@media screen and (max-width: 575px) {
.table-xs-responsive th, .table-xs-responsive td {
width: 100% !important;
display: block !important;
box-sizing:border-box;
}
}
@media screen and (max-width: 767px) {
.table.table-sm-responsive th, .table.table-sm-responsive td {
width: 100% !important;
display: block !important;
box-sizing:border-box;
}
}
@media screen and (max-width: 992px) {
.table.table-sm-responsive th, .table.table-sm-responsive td {
width: 100% !important;
display: block !important;
box-sizing:border-box;
}
}
@media screen and (max-width: 1200px) {
.table.table-sm-responsive th, .table.table-sm-responsive td {
width: 100% !important;
display: block !important;
box-sizing:border-box;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment