Top Banner
Responsive design: techniques and tricks to prepare your websites for the multi-screen future Andreas Bovens - Opera Software http://www.flickr.com/photos/redux/7145995789/
131

Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Sep 08, 2014

Download

Technology

Andreas Bovens

Websites are viewed on all kinds of devices, in all kinds of browsers. In this presentation, I explain how you can adapt your site to these different environments, using modern browser hooks and techniques.

I cover the various aspects (and some gotchas) of the viewport mechanism and media queries, and shed a light on how new CSS3 properties allow you to optimize images and videos for multiple screens.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Andreas Bovens - Opera Softwarehttp://www.flickr.com/photos/redux/7145995789/

Page 2: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Andreas Bovens - Opera Softwarehttp://www.flickr.com/photos/redux/7145995789/

Page 3: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@andreasbovens

Page 4: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Coherence Screen sharingSyncronization

Device shifting Complementarity Simultaneity

These patterns should help understand and define strategies for the multiscreen world.

“Patterns for Multiscreen Strategies”

By Precious http://slidesha.re/kiip5y

Page 5: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Coherence Screen sharingSyncronization

Device shifting Complementarity Simultaneity

These patterns should help understand and define strategies for the multiscreen world.

http://slidesha.re/kiip5y

Page 6: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Coherence

“A digital product or service looks and works coherently across devices. Features are optimized for specific device characteristics and usage scenarios.”

http://slidesha.re/kiip5y

Page 7: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

http://slidesha.re/kiip5yCoherence

Page 8: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 9: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

?

Page 10: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

small screen rendering aka single column view

Page 11: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 12: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 13: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 14: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

zoom and pan

Page 15: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 16: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 17: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 18: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 19: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 20: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 21: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 22: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

“Nice, but how can we control this zooming behavior?”

Page 23: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Let’s talk about the viewport mechanism

Page 24: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

This is the viewport.

Page 25: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Using a "viewport" meta tag in the <head> of the page...

<meta ...>

Page 26: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

...we can control page width & height, zoom level, etc.

Page 27: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 28: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 29: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

This works in:

with some exceptions ;-)

Page 31: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 32: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 33: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 34: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 35: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 36: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 37: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 38: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 39: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 40: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

Page 41: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

no viewport defined in <head>, so fallback to default of 980px,which is squeezed inside 320px.

Page 42: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=320">

HVGA portrait

Page 43: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=320">

HVGA portrait

Page 44: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=320">

HVGA portrait HVGA landscape

Page 45: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width">

HVGA portrait

Page 46: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

<meta name="viewport" content="width=device-width">

Page 47: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait HVGA landscape

<meta name="viewport" content="width=device-width">

Page 48: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

320px × 1.5 zoom

480px

HVGA

land

scap

eHV

GA la

ndsc

ape

Page 49: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=1">

HVGA portrait

Page 50: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=1">

HVGA portrait

Page 51: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=1">

HVGA portrait HVGA landscape

Page 52: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=1">

(same result as width=device-width)

HVGA portrait HVGA landscape

Page 53: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=0.5">

HVGA portrait HVGA landscape

Page 54: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="initial-scale=2">

HVGA portrait HVGA landscape

Page 55: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width">

+<div style="width: 600px">

Page 56: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width">

+<div style="width: 600px">

HVGA portrait

Page 57: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width, initial-scale=1">+<div style="width: 600px">

HVGA portrait

Page 58: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

maximum-scale=... , minimum-scale=...<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">

user-scalable=yes|no<meta name="viewport" content="width=320, user-scalable=no">

height=...<meta name="viewport" content="height=device-height">

other settings

Page 59: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

other settings

maximum-scale=... , minimum-scale=...<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">

user-scalable=yes|no<meta name="viewport" content="width=320, user-scalable=no">

height=...<meta name="viewport" content="height=device-height">

Page 60: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

other settings

maximum-scale=... , minimum-scale=...<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">

user-scalable=yes|no<meta name="viewport" content="width=320, user-scalable=no">

height=...<meta name="viewport" content="height=device-height">

Page 61: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

other settings

maximum-scale=... , minimum-scale=...<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">

user-scalable=yes|no<meta name="viewport" content="width=320, user-scalable=no">

height=...<meta name="viewport" content="height=device-height">

Page 62: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Important!Make sure to use commas, not semi-colons as delimiters between viewport values!

<meta name="viewport" content="initial-scale=1; user-scalable=no"> <meta name="viewport" content="initial-scale=1, user-scalable=no">

Page 63: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Android Browser doesn’t support user-scalable=no.

IE interprets width=device-width as 320px.

Safari on iPad always interprets width=device-width as 768px, although it’s 1024px wide in landscape mode. This can be overridden with initial-scale=1, which... triggers a zooming bug* on orientation change.

caveats

* Patch: https://github.com/scottjehl/iOS-Orientationchange-Fix

Page 65: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

So, how to use this?Sniff for mobile browsers maybe?

Page 66: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Better don’t sniff.

So, how to use this?Sniff for mobile browsers maybe?

Page 67: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 68: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 69: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 70: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 71: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 72: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 73: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 74: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Opera/9.80 (Macintosh; Intel Mac OS X 10.5.8; U; en) Presto/2.9.220 Version/12.00

Page 75: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 76: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 77: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 78: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 79: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 80: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

So, avoid sniffing,but if you really have to,provide a way for users to make corrections,and remember their preference.

Page 81: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

* always ask yourself why the mobile site should be different from the desktop site

So, avoid sniffing,but if you really have to*,provide a way for users to make corrections,and remember their preference.

Page 82: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

budget limitations

customer requirementstime restrictions

different layout neededcapabilities are different

* always ask yourself why the mobile site should be different from the desktop site

Page 83: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

budget limitations

customer requirementstime restrictions

capabilities are differentdifferent layout needed

* always ask yourself why the mobile site should be different from the desktop site

Page 84: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

budget limitations

customer requirementstime restrictions

capability detection

capabilities are differentdifferent layout needed

* always ask yourself why the mobile site should be different from the desktop site

Page 85: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

budget limitations

customer requirementstime restrictions

different layout needed

viewport + media queries

capabilities are different

capability detection

* always ask yourself why the mobile site should be different from the desktop site

Page 86: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Let’s talk about media queries

Page 87: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Media queries are conditional hooks for applying different CSS rules, depending on e.g. browser width or height, orientation, aspect ratio, etc.

Page 88: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Differently said, media queries allow you to optimize your site layout for all kinds of form factors.

Via http://mediaqueri.es/

Page 89: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@media screen and (min-width: 400px) and (max-width: 800px) { article { /* css for browsers with width ≥ 400px and ≤ 800px */ }

}

Page 90: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@media screen and (aspect-ratio: 16/9) and (orientation: landscape) { article { /* css for browsers with an aspect ratio of 16/9 and orientation is landscape */ }

}

Page 91: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@media screen and (max-width: 800px) { article { /* css for browsers with width ≤ 800px */ }

}@media screen and (max-width: 400px) { article { /* css for browsers with width ≤ 400px */ }

}

Page 92: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@media screen and (max-width: 800px) { article { /* css for browsers with width ≤ 800px */ }

}@media screen and (max-width: 400px) { article { /* css for browsers with width ≤ 400px */ }

}

Remember that mobile browsers have a default viewport width (e.g. 980px).For your mobile specific media queries to work, you need to set the viewport!

Page 93: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 94: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

default viewport.mobile specific media

queries not applied.

width=device-width. mobile specific media

queries applied.

Page 95: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

The viewport and media queries combo allows you to create just one responsive site that works everywhere.

Page 96: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Q: What do I start with, desktop or mobile?

A: Do mobile first, and build up your desktop styles from there.

Page 97: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Q: Which devices, screen sizes should I design for?

A: All of them! Use content breakpoints, instead of device breakpoints and you’ll get a long way.

Page 99: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Dealing withhigh-PPI “Retina” screens

Page 100: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

A pixel is not what it seems.Thus far, we’ve talked about pixels in terms of “CSS pixels”.One CSS pixel can be multiple device pixels.

Page 101: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

alm

ost W

VGA

port

rait

Page 102: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

HVGA portrait

alm

ost W

VGA

port

rait

Page 103: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Browser pretends that 480px is 320px.

alm

ost W

VGA

port

rait

Page 104: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

In most scenarios, you won’t have to worry about this.It just works.

Page 105: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

However, if you want tocontrol PPI related stuff, these are the things you can do:

Page 106: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

alm

ost W

VGA

port

rait

Set the meta viewport’starget-densitydpi to device-dpi.

(1)

Page 107: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

alm

ost W

VGA

port

rait

Everything is shown at 100%. One CSS pixel is equal to one device pixel.

(1)

Page 108: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 109: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

alm

ost W

VGA

port

rait

Use special device-pixel-ratio media query to serve PPI-specific CSS.

(2)

Page 110: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

alm

ost W

VGA

port

rait

I’ve set the 1500×1500px background-image to repeat every 1000px, making it crispy again. The rest of the content is still scaled 150%.

Page 111: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 112: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

caveats

-o-max/min-device-pixel-ratio uses fractions instead of numbers. So 3/2, not 1.5.

Watch out for max/min--moz-device-pixel-ratio.

Page 113: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@media screen and (min-device-pixel-ratio: 3/2) { body {background-size: 250px;}}would become:

@media screen and (min-resolution: 1.5dppx) { body {background-size: 250px;}}

max/min-device-pixel-ratio might be dropped, and we get a resolution media query instead.

Page 114: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

alm

ost W

VGA

port

rait

Use high-res images to preserve crispiness.

(3)

Page 115: Responsive design: techniques and tricks to prepare your websites for the multi-screen future
Page 117: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<picture><source media="(orientation: landscape)" srcset="long.jpg 1x, long2.jpg 2x"><source media="(orientation: portrait)" srcset="tall.jpg 1x, tall2.jpg 2x"><img src="fallback.jpg" /></picture>

You will be able to specify multiple image sources:

Page 118: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<video><source type="video/webm" src="small.webm" media="all and (max-width: 480px)"><source type="video/webm" src="large.webm" media="all and (min-width: 481px)" > </video>

You already can specify multiple video sources:

Page 119: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Sidenote about another responsive image technique:

object-fit and object-position allow you to crop images

Page 120: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

simple resize

Page 121: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

resize with object-fit and object-position adjustments

Page 124: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Why do all this viewport stuff with <meta> tags? Isn’t this something for CSS?

Page 126: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

becomes

@viewport {width: device-width;zoom: 1;user-zoom: fixed;

}

Page 127: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

becomes

@-o-/-ms-viewport {width: device-width;zoom: 1;user-zoom: fixed;

}

Page 129: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Andreas Bovens - Opera Softwarehttp://www.flickr.com/photos/redux/7145995789/

present

Page 130: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Responsive design: techniques and tricks to prepare your websites for the multi-screen future

Andreas Bovens - Opera Softwarehttp://www.flickr.com/photos/redux/7145995789/

present

Page 131: Responsive design: techniques and tricks to prepare your websites for the multi-screen future

@andreasbovens

Corkboard background: http://psd.tutsplus.com/freebies/texture/corkboard-texture-pack/

Thank you!

Glyphicons: http://glyphicons.com/glyphicons-licenses/

Dosis font: http://www.impallari.com/dosis