Skip to content

Instantly share code, notes, and snippets.

@markkimsal
Created December 23, 2015 17:19
Show Gist options
  • Save markkimsal/5e04695bf3f454b19664 to your computer and use it in GitHub Desktop.
Save markkimsal/5e04695bf3f454b19664 to your computer and use it in GitHub Desktop.
Responsive table columns css
// Extra small screen / phone
@screen-xs: 480px;
@screen-xs-min: @screen-xs;
// Small screen / tablet / phone horizontal
@screen-sm: 640px;
@screen-sm-min: @screen-sm;
// Medium screen / desktop
@screen-md: 768px;
@screen-md-min: @screen-md;
// Large screen / wide desktop
@screen-lg: 990px;
@screen-lg-min: @screen-lg;
// So media queries don't overlap when required, provide a maximum
@screen-xs-max: (@screen-sm-min - 1);
@screen-sm-max: (@screen-md-min - 1);
@screen-md-max: (@screen-lg-min - 1);
/* tables */
/* can remove th/td when chrome fixes bug */
/* https://code.google.com/p/chromium/issues/detail?id=174167 */
.table-responsive table thead tr th,
.table-responsive table tbody tr td,
.table-responsive table colgroup col {
visibility: visible;
}
@media screen and (max-width: @screen-md-max) {
/* can remove th/td when chrome fixes bug */
/* https://code.google.com/p/chromium/issues/detail?id=174167 */
table thead tr th.tcl-lg ,
table tbody tr td.tcl-lg ,
table colgroup col.tcl-lg {
display:none;
visibility: collapse;
width:0;
}
}
@media screen and (max-width: @screen-sm-max) {
/* can remove th/td when chrome fixes bug */
/* https://code.google.com/p/chromium/issues/detail?id=174167 */
table thead tr th.tcl-md ,
table tbody tr td.tcl-md ,
table colgroup col.tcl-md {
display:none;
visibility: collapse;
width:0;
}
table thead tr th.tcl-lg ,
table tbody tr td.tcl-lg ,
table colgroup col.tcl-lg {
display:none;
visibility: collapse;
width:0;
}
}
@media screen and (max-width: @screen-xs-max) {
/* can remove th/td when chrome fixes bug */
/* https://code.google.com/p/chromium/issues/detail?id=174167 */
table colgroup col.tcl-sm ,
table thead tr th.tcl-sm ,
table tbody tr td.tcl-sm {
display:none;
visibility: collapse;
width:0;
}
table thead tr th.tcl-md ,
table tbody tr td.tcl-md ,
table colgroup col.tcl-md {
display:none;
visibility: collapse;
width:0;
}
table thead tr th.tcl-lg ,
table tbody tr td.tcl-lg ,
table colgroup col.tcl-lg {
display:none;
visibility: collapse;
width:0;
}
}
<html>
<head>
<link ref="stylesheet" href="main.css">
</head>
<body>
<table border="1">
<colgroup>
<col class="tcl-md">
<col class="tcl-lg">
</colgroup>
<tbody>
<tr>
<td class="tcl-md"> data 1</td>
<td class="tcl-lg"> data 2 </td>
</tr>
<tr>
<td class="tcl-md"> data 3</td>
<td class="tcl-lg"> data 4 </td>
</tr>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment