A Pen by Stan Williams on CodePen.
Created
August 19, 2018 03:57
-
-
Save stanwmusic/d1142fdaa2ed92b348cfee0b2c9bf35f to your computer and use it in GitHub Desktop.
Responsive Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Responsive Table</h1> | |
<table class="table table--responsive"> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Twitter</th> | |
<th>Website</th> | |
</tr> | |
</thead> | |
<tr> | |
<td data-th="Name">Stan Williams</td> | |
<td data-th="Twitter">@Stanssongs</td> | |
<td data-th="Website"><a href="http://stanwilliams.org" target="_blank">https://stanwilliams.org</a></td> | |
</tr> | |
<tr> | |
<td data-th="Name">Stan Williams</td> | |
<td data-th="Twitter">@Stanssongs</td> | |
<td data-th="Website"><a href="https://stanwilliamsmusic.com" target="_blank">http://stanwilliamsmusic.com</a></td> | |
</tr> | |
<tr> | |
<td data-th="Name">Stan Williams</td> | |
<td data-th="Twitter">@Stanssongs</td> | |
<td data-th="Website"><a href="http://stanwilliams.org" target="_blank">https://stanwilliams.org</a></td> | |
</tr> | |
<tr> | |
<td data-th="Name">Stan Williams</td> | |
<td data-th="Twitter">@Stanssongs</td> | |
<td data-th="Website"><a href="http://swsitedesign.com" target="_blank">https://swsitedesign.com</a></td> | |
</tr> | |
</table> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "lesshat"; | |
// Demo Styles | |
body { | |
color:#fff; | |
background-color: #000; | |
padding: 30px; | |
} | |
// Default table styles | |
.table { | |
width: 100%; | |
background: #202020; | |
border-collapse: collapse; | |
// Zebra stripe the rows. | |
/* tr { | |
&:nth-of-type(odd) { | |
background: #f1f1f1; | |
} | |
&:nth-of-type(even) { | |
background: #f6f6f6; | |
} | |
}*/ | |
th { | |
color: #fff; | |
background: #333; | |
font-weight: bold; | |
} | |
td, th { | |
padding: 10px; | |
//border: 1px solid #fff; | |
text-align: left; | |
} | |
} | |
// Small screens | |
@media only screen and (max-width: 768px) { | |
.table--responsive { | |
table, thead, tbody, th, td, tr { | |
display: block; | |
} | |
/* Hide table headers (but not display: none;, for accessibility) */ | |
thead tr { | |
position: absolute; | |
top: -9999px; | |
left: -9999px; | |
} | |
td { | |
border: none; | |
border-bottom: 1px solid #fff; | |
position: relative; | |
padding-left: 50%; | |
} | |
td:before { | |
position: absolute; | |
width: 45%; | |
top: 6px; | |
left: 6px; | |
white-space: nowrap; | |
content: attr(data-th); | |
font-weight: bold; | |
width: 6.5em; | |
color: #3498db; | |
display: inline-block; | |
} | |
} | |
} | |
// Very small screens | |
@media only screen and (max-width : 480px) { | |
.table--responsive { | |
td { | |
border: none; | |
border-bottom: 1px solid #fff; | |
position: relative; | |
padding-left: 10px; | |
padding-top: 50px; | |
padding-bottom: 10px; | |
} | |
td:before { | |
position: absolute; | |
top: 20px; | |
left: 10px; | |
white-space: nowrap; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo / preview:
https://codepen.io/Stanssongs/full/rZBjBg/