Created
July 28, 2018 14:47
-
-
Save olivx/6a3b2b4bf2ce412e7d7b8d63cbca34ad to your computer and use it in GitHub Desktop.
responsivel table
This file contains hidden or 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
/* | |
Max width before this PARTICULAR table gets nasty. This query will take effect for any screen smaller than 760px and also iPads specifically. | |
*/ | |
@media | |
only screen | |
and (max-width: 760px), (min-device-width: 768px) | |
and (max-device-width: 1024px) { | |
/* Force table to not be like tables anymore */ | |
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; | |
} | |
tr { | |
margin: 0 0 1rem 0; | |
} | |
tr:nth-child(odd) { | |
background: #eee; | |
} | |
td { | |
/* Behave like a "row" */ | |
border: none; | |
border-bottom: 1px solid #ccc; | |
position: relative; | |
padding-left: 50%; | |
} | |
td:before { | |
/* Now like a table header */ | |
position: absolute; | |
/* Top/left values mimic padding */ | |
top: 0; | |
left: 6px; | |
width: 45%; | |
padding-right: 10px; | |
white-space: nowrap; | |
} | |
/* | |
Label the data | |
You could also use a data-* attribute and content for this. That way "bloats" the HTML, this way means you need to keep HTML and CSS in sync. Lea Verou has a clever way to handle with text-shadow. | |
*/ | |
td:nth-of-type(1):before { content: "First Name"; } | |
td:nth-of-type(2):before { content: "Last Name"; } | |
td:nth-of-type(3):before { content: "Job Title"; } | |
td:nth-of-type(4):before { content: "Favorite Color"; } | |
td:nth-of-type(5):before { content: "Wars of Trek?"; } | |
td:nth-of-type(6):before { content: "Secret Alias"; } | |
td:nth-of-type(7):before { content: "Date of Birth"; } | |
td:nth-of-type(8):before { content: "Dream Vacation City"; } | |
td:nth-of-type(9):before { content: "GPA"; } | |
td:nth-of-type(10):before { content: "Arbitrary Data"; } | |
} |
This file contains hidden or 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
<table data-role="table" id="movie-table-custom" data-mode="reflow" class="movie-list table-stroke"> | |
<thead> | |
<tr> | |
<th data-priority="1">Rank</th> | |
<th style="width:40%">Movie Title</th> | |
<th data-priority="2">Year</th> | |
<th data-priority="3"><abbr title="Rotten Tomato Rating">Rating</abbr></th> | |
<th data-priority="4">Reviews</th> | |
<th data-priority="4">Director</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<th style="display:none">1</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Citizen_Kane" data-rel="external">Citizen Kane</a></td> | |
<td>1941</td> | |
<td>100%</td> | |
<td>74</td> | |
<td>Orson Welles</td> | |
</tr> | |
<tr> | |
<th>2</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Casablanca_(film)" data-rel="external">Casablanca</a></td> | |
<td>1942</td> | |
<td>97%</td> | |
<td>64</td> | |
<td>Michael Curtiz</td> | |
</tr> | |
<tr> | |
<th>3</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/The_Godfather" data-rel="external">The Godfather</a></td> | |
<td>1972</td> | |
<td>97%</td> | |
<td>87</td> | |
<td>Francis Ford Coppola</td> | |
</tr> | |
<tr> | |
<th>4</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Gone_with_the_Wind_(film)" data-rel="external">Gone with the Wind</a></td> | |
<td>1939</td> | |
<td>96%</td> | |
<td>87</td> | |
<td>Victor Fleming</td> | |
</tr> | |
<tr> | |
<th>5</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Lawrence_of_Arabia_(film)" data-rel="external">Lawrence of Arabia</a></td> | |
<td>1962</td> | |
<td>94%</td> | |
<td>87</td> | |
<td>Sir David Lean</td> | |
</tr> | |
<tr> | |
<th>6</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Dr._Strangelove" data-rel="external">Dr. Strangelove Or How I Learned to Stop Worrying and Love the Bomb</a></td> | |
<td>1964</td> | |
<td>92%</td> | |
<td>74</td> | |
<td>Stanley Kubrick</td> | |
</tr> | |
<tr> | |
<th>7</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/The_Graduate" data-rel="external">The Graduate</a></td> | |
<td>1967</td> | |
<td>91%</td> | |
<td>122</td> | |
<td>Mike Nichols</td> | |
</tr> | |
<tr> | |
<th>8</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/The_Wizard_of_Oz_(1939_film)" data-rel="external">The Wizard of Oz</a></td> | |
<td>1939</td> | |
<td>90%</td> | |
<td>72</td> | |
<td>Victor Fleming</td> | |
</tr> | |
<tr> | |
<th>9</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Singin%27_in_the_Rain" data-rel="external">Singin' in the Rain</a></td> | |
<td>1952</td> | |
<td>89%</td> | |
<td>85</td> | |
<td>Stanley Donen, Gene Kelly</td> | |
</tr> | |
<tr> | |
<th>10</th> | |
<td class="title"><a href="http://en.wikipedia.org/wiki/Inception" data-rel="external">Inception</a></td> | |
<td>2010</td> | |
<td>84%</td> | |
<td>78</td> | |
<td>Christopher Nolan</td> | |
</tr> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment