Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pixelchar/9550415 to your computer and use it in GitHub Desktop.
Save pixelchar/9550415 to your computer and use it in GitHub Desktop.
A Pen by Charlie Cathcart.
<div class="container">
<table class="responsive-table">
<caption>Top 10 Grossing Animated Films of All Time</caption>
<thead>
<tr>
<th scope="col">Film Title</th>
<th scope="col">Released</th>
<th scope="col">Studio</th>
<th scope="col">Worldwide Gross</th>
<th scope="col">Domestic Gross</th>
<th scope="col">Foreign Gross</th>
<th scope="col">Budget</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7">Sources: <a href="http://en.wikipedia.org/wiki/List_of_highest-grossing_animated_films" rel="external">Wikipedia</a> &amp; <a href="http://www.boxofficemojo.com/genres/chart/?id=animation.htm" rel="external">Box Office Mojo</a>. Data is current as of March 12, 2014</td>
</tr>
</tfoot>
<tbody>
<tr>
<th scope="row">Toy Story 3</th>
<td data-title="Released">2010</td>
<td data-title="Studio">Disney Pixar</td>
<td data-title="Worldwide Gross" data-type="currency">$1,063,171,911</td>
<td data-title="Domestic Gross" data-type="currency">$415,004,880</td>
<td data-title="Foreign Gross" data-type="currency">$648,167,031</td>
<td data-title="Budget" data-type="currency">$200,000,000</td>
</tr>
<tr>
<th scope="row">Frozen</th>
<td data-title="Released">2013</td>
<td data-title="Studio">Disney</td>
<td data-title="Worldwide Gross" data-type="currency">$1,010,014,508</td>
<td data-title="Domestic Gross" data-type="currency">$393,614,508</td>
<td data-title="Foreign Gross" data-type="currency">$616,400,000</td>
<td data-title="Budget" data-type="currency">$150,000,000</td>
</tr>
<tr>
<th scope="row">The Lion King</th>
<td data-title="Released">1994</td>
<td data-title="Studio">Disney</td>
<td data-title="Worldwide Gross" data-type="currency">$987,483,777</td>
<td data-title="Domestic Gross" data-type="currency">$422,783,777</td>
<td data-title="Foreign Gross" data-type="currency">$564,700,000</td>
<td data-title="Budget" data-type="currency">$45,000,000</td>
</tr>
<tr>
<th scope="row">Despicable Me 2</th>
<td data-title="Released">2013</td>
<td data-title="Studio">Universal</td>
<td data-title="Worldwide Gross" data-type="currency">$970,761,885</td>
<td data-title="Domestic Gross" data-type="currency">$368,061,265</td>
<td data-title="Foreign Gross" data-type="currency">$602,700,620</td>
<td data-title="Budget" data-type="currency">$76,000,000</td>
</tr>
<tr>
<th scope="row">Finding Nemo</th>
<td data-title="Released">2003</td>
<td data-title="Studio">Pixar</td>
<td data-title="Worldwide Gross" data-type="currency">$936,743,261</td>
<td data-title="Domestic Gross" data-type="currency">$380,843,261</td>
<td data-title="Foreign Gross" data-type="currency">$555,900,000</td>
<td data-title="Budget" data-type="currency">$94,000,000</td>
</tr>
<tr>
<th scope="row">Shrek 2</th>
<td data-title="Released">2004</td>
<td data-title="Studio">Dreamworks</td>
<td data-title="Worldwide Gross" data-type="currency">$919,838,758</td>
<td data-title="Domestic Gross" data-type="currency">$441,226,247</td>
<td data-title="Foreign Gross" data-type="currency">$478,612,511</td>
<td data-title="Budget" data-type="currency">$150,000,000</td>
</tr>
<tr>
<th scope="row">Ice Age: Dawn of the Dinosaurs</th>
<td data-title="Released">2009</td>
<td data-title="Studio">Fox</td>
<td data-title="Worldwide Gross" data-type="currency">$886,686,817</td>
<td data-title="Domestic Gross" data-type="currency">$196,573,705</td>
<td data-title="Foreign Gross" data-type="currency">$690,113,112 </td>
<td data-title="Budget" data-type="currency">$90,000,000</td>
</tr>
<tr>
<th scope="row">Ice Age: Continental Drift</th>
<td data-title="Released">2012</td>
<td data-title="Studio">Fox</td>
<td data-title="Worldwide Gross" data-type="currency">$877,244,782</td>
<td data-title="Domestic Gross" data-type="currency">$161,321,843</td>
<td data-title="Foreign Gross" data-type="currency">$715,922,939</td>
<td data-title="Budget" data-type="currency">$95,000,000</td>
</tr>
<tr>
<th scope="row">Shrek the Third</th>
<td data-title="Released">2007</td>
<td data-title="Studio">Dreamworks</td>
<td data-title="Worldwide Gross" data-type="currency">$798,958,162</td>
<td data-title="Domestic Gross" data-type="currency">$322,719,944</td>
<td data-title="Foreign Gross" data-type="currency">$476,238,218</td>
<td data-title="Budget" data-type="currency">$160,000,000</td>
</tr>
<tr>
<th scope="row">Shrek Forever After</th>
<td data-title="Released">2010</td>
<td data-title="Studio">Dreamworks</td>
<td data-title="Worldwide Gross" data-type="currency">$752,600,867</td>
<td data-title="Domestic Gross" data-type="currency">$238,736,787</td>
<td data-title="Foreign Gross" data-type="currency">$513,864,080 </td>
<td data-title="Budget" data-type="currency">$165,000,000</td>
</tr>
</tbody>
</table>
</div>

Responsive & Accessible Data Table

Mobile-first responsive and accessible data table. At narrower view ports, the thead is hidden, rows are turned into cards with labels shown using a data-* attribute.

A Pen by Charlie Cathcart on CodePen.

License.

@import "compass";
// Breakpoints
$bp-maggie: 15em;
$bp-lisa: 30em;
$bp-bart: 48em;
$bp-marge: 62em;
$bp-homer: 75em;
// Styles
* {
@include box-sizing(border-box);
&:before,
&:after {
@include box-sizing(border-box);
}
}
body {
font-family: $helvetica;
color: rgba(94,93,82,1);
}
a {
color: rgba(51,122,168,1);
&:hover,
&:focus {
color: rgba(75,138,178,1);
}
}
.container {
margin: 5% 3%;
@media (min-width: $bp-bart) {
margin: 2%;
}
@media (min-width: $bp-homer) {
margin: 2em auto;
max-width: $bp-homer;
}
}
.responsive-table {
width: 100%;
margin-bottom: 1.5em;
@media (min-width: $bp-bart) {
font-size: .9em;
}
@media (min-width: $bp-marge) {
font-size: 1em;
}
thead {
// Accessibly hide <thead> on narrow viewports
position: absolute;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
padding: 0;
border: 0;
height: 1px;
width: 1px;
overflow: hidden;
@media (min-width: $bp-bart) {
// Unhide <thead> on wide viewports
position: relative;
clip: auto;
height: auto;
width: auto;
overflow: auto;
}
th {
background-color: rgba(29,150,178,1);
border: 1px solid rgba(29,150,178,1);
font-weight: normal;
text-align: center;
color: white;
&:first-of-type {
text-align: left;
}
}
}
// Set these items to display: block for narrow viewports
tbody,
tr,
th,
td {
display: block;
padding: 0;
text-align: left;
white-space: normal;
}
tr {
@media (min-width: $bp-bart) {
// Undo display: block
display: table-row;
}
}
th,
td {
padding: .5em;
vertical-align: middle;
@media (min-width: $bp-lisa) {
padding: .75em .5em;
}
@media (min-width: $bp-bart) {
// Undo display: block
display: table-cell;
padding: .5em;
}
@media (min-width: $bp-marge) {
padding: .75em .5em;
}
@media (min-width: $bp-homer) {
padding: .75em;
}
}
caption {
margin-bottom: 1em;
font-size: 1em;
font-weight: bold;
text-align: center;
@media (min-width: $bp-bart) {
font-size: 1.5em;
}
}
tfoot {
font-size: .8em;
font-style: italic;
@media (min-width: $bp-marge) {
font-size: .9em;
}
}
tbody {
@media (min-width: $bp-bart) {
// Undo display: block
display: table-row-group;
}
tr {
margin-bottom: 1em;
border: 2px solid rgba(29,150,178,1);
@media (min-width: $bp-bart) {
// Undo display: block
display: table-row;
border-width: 1px;
}
&:last-of-type {
margin-bottom: 0;
}
&:nth-of-type(even) {
@media (min-width: $bp-bart) {
background-color: rgba(94,93,82,.1);
}
}
}
th[scope="row"] {
background-color: rgba(29,150,178,1);
color: white;
@media (min-width: $bp-bart) {
background-color: transparent;
color: rgba(94,93,82,1);
text-align: left;
}
}
td {
text-align: right;
@media (min-width: $bp-lisa) {
border-bottom: 1px solid rgba(29,150,178,1);
}
@media (min-width: $bp-bart) {
text-align: center;
}
}
td[data-type=currency] {
text-align: right;
}
td[data-title]:before {
content: attr(data-title);
float: left;
font-size: .8em;
color: rgba(94,93,82,.75);
@media (min-width: $bp-lisa) {
font-size: .9em;
}
@media (min-width: $bp-bart) {
// Don’t show data-title labels
content: none;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment