Future-proof Responsive Design

By Florian Rivoal / @frivoal

Slides at florian.rivoal.net/talks/responsive-design/

Who am I?

Vivliostyle logo
Work at Vivliostyle
Opera Software logo
Used to work at Opera

What is responsive design?

Designing web content so that it works on any device, and adapt itself to provide the best experience possible given the caracteristics of the environement.

Responsive is nothing new

The first web site ever was responsive.

http://info.cern.ch/hypertext/WWW/TheProject.html

How did the web become non-responsive?

Beyond longform text documents

→ Rigid and fragile layouts on most sites

Mobile browsers and the layout viewport

A website viewed in a phone, using a layout viewport larger than the phone screen

Fixing the viewport

The viewport meta tag

<meta name="viewport" content="width=device-width, initial-scale=1">
A website viewed in a phone, using a layout viewport larger than the phone screen
Without meta viewport
A website viewed in a phone, with a layout viewport matching the phone screen
With meta viewport

If you want to know everything about viewports, PPK has a great presentation

@viewport

Alternative to the meta viewport in css

@viewport { width: auto; }

This is specified in CSS Device Adaptation

Support: Edge, IE>=10, IE Mobile>= 8, Opera Mobile 12, Opera Mini

It also explains mobile browsers’ default behavior:

@viewport { min-width: 980px; }

@viewport beyond mobile

It also works on desktop

@viewport { min-width: 500px; }
@media (min-width: 500px) {
  @-ms-viewport { width: 500px; }
  /* IE&Edge don't support @viewport’s min-width */
}

Demo at http://jsbin.com/kimone/

Media Queries

Desktop, laptop, tablet and phone

Simple media queries

Basic building block of responsive design

aside { float: right; }
@media (max-width: 500px) {
aside { float: none; }
}

Robust media queries

Don't base break-points on devices you test for

@media (width: 320px) { ... } /* iPhone screen width */
@media (max-width: 375px) { ... } /* iPhone 6 screen width */

Base your break points on your content instead

@media (max-width: 500px) { ... } /* Size below which… */
@media (max-width: 45em) { ... } /* …your site would break */

Media Queries on SVG

See the Pen London underground sign by Ana Sampaio (@anaisampaio) on CodePen.

Credit to Ana Sampaio

Fixing the layout

CSS 3 introduces expressive and robust new layout tools

CSS Multi-column layout

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
columns: 2
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
columns: 150px

Flexbox

Foo
Bar
Baz
Foo
Bar
Baz

CSS Grid layout

<div id="grid">
  <div id="title">Game Title</div>
  <div id="score">Score</div>
  <div id="stats">Stats</div>
  <div id="board">Board</div>
  <div id="controls">Controls</div>
</div>
#grid {
  display: grid;
  grid-template-areas: "title stats"
                       "score stats"
                       "board board"
                       "ctrls ctrls";
  grid-template-columns: auto minmax(min-content, 1fr);
  grid-template-rows: auto auto minmax(min-content, 1fr) auto
}
#title    { grid-area: title }
#score    { grid-area: score }
#stats    { grid-area: stats }
#board    { grid-area: board }
#controls { grid-area: ctrls }

Media Queries, revisited

Desktop, laptop, tablet and phone
Nintendo DS
Nintendo Wii
Smart watch
Ebook reader
Printed book

Media types are dead ...

@media print { /* ... */ }

screen, print, handheld, projection, tv, ...

... long live media features

pointerhoverupdateoverflow-blockscripting
laptopfinehoverfastscrollenabled
phonecoarsenonefastscrollenabled
Wiicoarsehovernormalscrollenabled
printnonenonenonepagedinitial-only
e-inknonenoneslowpagedenabled
Vivliostyle.jsfinehovernormalpagedenabled

Example

@media screen {
  .menu ul { display: none; }
  .menu:hover ul { display: block; }
  a { text-decoration: none; }
  a:hover { text-decoration: underline; }
}

@media print {
  body { font-family: serif; }
  .js-ads { display: none; }
}

@media (width: 320px) /*iPhone*/ {
  button { min-height: 40px; }
} 
@media (hover) and (update) {
  .menu ul { display: none; }
  .menu:hover ul { display: block; }
  a { text-decoration: none; }
  a:hover { text-decoration: underline; }
}
@media (min-resolution: 2dppx) {
  body { font-family: serif; }
}
@media (scripting: none) {
  .js-ads { display: none; }
}
@media (pointer: coarse) {
  button { min-height: 40px; }
}

The End


florian.rivoal.net/talks/responsive-design/

@frivoal