A presentation at CSS Dev Conf in October 2017 in New Orleans, LA, USA by Stephanie Hobson
Flipping Tables
Displaying Data on Small Screens
#flipdata
Tables
Am I right?
( ý ° □ °) ý—
Í“Í
• When to use tables ( ý ° □ °) ý—
• When to use tables • Creating structure with HTML ( ý ° □ °) ý—
• When to use tables • Creating structure with HTML
• Designing tables ( ý ° □ °) ý—
• Designing tables • Adding style with CSS ( ý ° □ °) ý—
• Designing tables • Adding style with CSS • Adapting tables to small screens ( ý ° □ °) ý—
Sorry!
When to use tables
When to use tables • Sort • Compare • Cross Reference • Calculations
When to use tables not
.players { column-count:2;
} When to use tables not
img { float: left; } When to use tables not
/* Nicole Sullivan’s Media Object */
layout When to use tables not
Tables Good • Sort • Compare • Cross Reference • Calculations
layout Tables Bad
Creating structure with HTML
<col />
Designing tables
Designing tables • Provide a caption • Identify columns, rows, and headers
• Enhance readability • Group similar data • Smart defaults
Designing tables • Contrast • Repetition • Alignment • Proximity
John Maeda, Designer “Simplicity is about subtracting the obvious and adding the meaningful.”
Designing tables • www.darkhorseanalytics.com/blog/ clear-off-the-table/
• www.behance.net/gallery/Designing- Effective-Data-Tables/885004 • understandinggraphics.com/design/ data-table-design/
Adding style with CSS
Adding style with CSS border-collapse : separate; border-spacing: 2px;
Adding style with CSS border-collapse : separate; border-spacing: 10px;
Adding style with CSS border-collapse : collapse; border-spacing: 10px;
Adding style with CSS caption-side: top ;
Adding style with CSS caption-side: top-outside ;
Adding style with CSS caption-side: bottom ;
Adding style with CSS caption-side: right ;
figure { display: table;
caption-side: bottom; } figcaption { display: table-caption; } Adding style with CSS
Adding style with CSS vertical-align: middle;
Adding style with CSS .parent { display: table; } .child { display: table-cell; height: 100vh; vertical-align: middle; }
Adding style with CSS th { } tbody th { } tbody th[scope="row"] { } th.special { }
Adding style with CSS colgroup { } col { }
.points { background-color: #eee; } Adding style with CSS
Adding style with CSS tbody td:nth-child(5) { background-color: #ddd; }
Adding style with CSS tr:nth-child(even) { background-color: #ddd; }
Adding style with CSS A note about screen readers
layout Adding style with CSS
Adding style with CSS • A note about screen readers
Adapting tables to small screens
Adapting tables to small screens • Shrink
Shrink
font-size: 1rem;
Adapting tables to small screens • Shrink • Linearize or flip ( ý ° □ °) ý—
Linearize table, thead, tbody, tfoot, tr, th, td { display: block; }
Linearize
Linearize td:nth-child(3)::before { content: 'Goals:' ; } td:nth-child(4)::before { content: 'Assists:'; }
Linearize .goals ::before { content: 'Goals:'; } .assists ::before { content: 'Assists:'; } .points ::before { content: 'Points:';}
}
• Remove
Remove
Remove Activity
Remove Nutrition
• Remove • Scroll
Scroll
Scroll table{
display: block;
overflow: scroll;
• Remove • Scroll • Replace
Replace
Replace 0 1.25 2.5 3.75 5 Jan Feb Mar Apr
First quarter profits rose 2.5%. See the 2016 annual report for the breakdown. Replace
• Remove • Scroll • Replace • Combo
Combo
Example http://v6.robweychert.com/blog/2017/10/robtober/
Example
Combo • Shrink • Linearize or flip ( ý ° □ °) ý—
Case Study
Case Study • github.com/mdn/browser-compat-data
• npm install mdn-browser-compat-data
Case Study @media
(min-width: 47.9385em) and (max-width: 63.9375em) {
… }
Case Study @supports (display: grid) {
Case Study .bc-table tr {
display: grid; }
Case Study .bc-table-10 tr { grid-template-columns:
repeat(10 , 1fr); }
Case Study @for $num from 4 through 14{ . bc-table-#{$num} tr { grid-template-columns:
repeat(#{$num}, 1fr); } }
Case Study .bc-table-4 tr { grid-template-columns:repeat(4, 1fr);}
.bc-table-5 tr { grid-template-columns:repeat(5, 1fr);}
.bc-table-6 tr { grid-template-columns:repeat(6 , 1fr);}
Case Study .bc-table tbody th {
grid-column-start: 1; grid-column-end: last-line;
Case Study .platform -desktop, .platform-mobile { grid-column-end: span 5 ; }
Case Study @for $num from 4 through 14 { th[class^=platform-][colspan=‘ #{$num}']{
grid-column-end: span #{$num};
} }
Case Study th[class^=platform-][colspan='4'] { grid-column-end: span 4; }
th[class^=platform-][colspan='5'] { grid-column-end: span 5; }
th[class^=platform-][colspan='6'] { grid-column-end: span 6; }
Case Study table, thead, tbody, tr, th, td { display: block; }
Case Study td.browser-firefox:before { content: ' '; }
I Like To Make Websites Everyone Can Use
stephaniehobson.ca
@stephaniehobson