adaptive layouts - standards>next london 28.05.2011

65
Adaptive layouts Patrick H. Lauke / standards>next / London / 28 May 2011 RANDOM THOUGHTS ON MAKING YOUR SITE CROSS-DEVICE FRIENDLY

Upload: patrick-lauke

Post on 28-Jan-2015

106 views

Category:

Technology


0 download

DESCRIPTION

Random thoughts on making your site cross-device friendlystandards>next / London / 28 May 2011

TRANSCRIPT

Page 1: Adaptive Layouts - standards>next London 28.05.2011

Adaptive layouts

Patrick H. Lauke / standards>next / London / 28 May 2011

RANDOM THOUGHTS ON MAKING YOUR SITE CROSS-DEVICE FRIENDLY

Page 2: Adaptive Layouts - standards>next London 28.05.2011

we need a site that works on mobile

Page 3: Adaptive Layouts - standards>next London 28.05.2011

we need a site that works on iPhone

Page 4: Adaptive Layouts - standards>next London 28.05.2011

...works on iPhone...oh, and iPad

Page 5: Adaptive Layouts - standards>next London 28.05.2011

“remove iPhone from ass”Peter-Paul Koch, The iPhone obsession

www.quirksmode.org/blog/archives/2010/02/the_iphone_obse.html

Page 6: Adaptive Layouts - standards>next London 28.05.2011

make your site work on all (most) mobile devices

Page 7: Adaptive Layouts - standards>next London 28.05.2011
Page 8: Adaptive Layouts - standards>next London 28.05.2011
Page 9: Adaptive Layouts - standards>next London 28.05.2011

what exactly is a “mobile device”?

Page 10: Adaptive Layouts - standards>next London 28.05.2011
Page 11: Adaptive Layouts - standards>next London 28.05.2011
Page 12: Adaptive Layouts - standards>next London 28.05.2011

don't do browser sniffing

http://www.flickr.com/photos/timdorr/2096272747/

Page 13: Adaptive Layouts - standards>next London 28.05.2011

CSS 2 Media Types

Page 14: Adaptive Layouts - standards>next London 28.05.2011

Media types

all brailleembossed handheldprint projectionscreen speechtty tv

Page 15: Adaptive Layouts - standards>next London 28.05.2011

media="handheld"

Page 16: Adaptive Layouts - standards>next London 28.05.2011

CSS 2.1 Media Types

<link rel="stylesheet" ... media="print" href="...">

@import url("...") print;

@media print { // insert CSS rules here}

Page 17: Adaptive Layouts - standards>next London 28.05.2011

CSS 3 Media Queries“...the new hotness” Jeffrey Zeldman

http://www.zeldman.com/2010/04/08/best-aea-yet/

Page 18: Adaptive Layouts - standards>next London 28.05.2011

CSS 3 Media Queries

● build and extend CSS 2.1 Media Types● more granular control of capabilities

http://www.w3.org/TR/css3-mediaqueries/

Page 19: Adaptive Layouts - standards>next London 28.05.2011

Media featureswidth colorheight color-indexdevice-width monochromedevice-height resolutionorientation scanaspect-ratio griddevice-aspect-ratio

Page 20: Adaptive Layouts - standards>next London 28.05.2011

CSS 3 Media Queries

<link rel="stylesheet" ... media="screen and (max-width:480px)" href="...">

@import url("...") screen and (max-width:480px);

@media screen and (max-width:480px) { // insert CSS rules here}

Page 21: Adaptive Layouts - standards>next London 28.05.2011

Multiple expressions – and keyword@media screen and (min-width:180px) and (max-width:480px) { // screen device and width > 180px // and width < 480px }

Page 22: Adaptive Layouts - standards>next London 28.05.2011

Multiple expressions – comma separated@media screen and (min-width:800px), print and (min-width:20em) { // screen device with width > 800px // or print device with width > 20em }

Page 23: Adaptive Layouts - standards>next London 28.05.2011

Negative expressions – not keyword@media not screen and (min-width:800px) { // not applied to screen device // with width > 800px}

Page 24: Adaptive Layouts - standards>next London 28.05.2011

Negative expressions – only keyword@media only screen and (min-width:800px) { // only applied to screen device // with width > 800px}

Page 25: Adaptive Layouts - standards>next London 28.05.2011

Multiple media queries@media screen and (max-width:480px) { // screen device and width < 480px }

@media screen and (max-width:980px) { // screen device and width < 980px }

@media screen and (min-width:980px) { // screen device and width > 980px }

Page 26: Adaptive Layouts - standards>next London 28.05.2011

www.alistapart.com/articles/responsive-web-design

Page 27: Adaptive Layouts - standards>next London 28.05.2011

http://mediaqueri.es

Page 28: Adaptive Layouts - standards>next London 28.05.2011

http://mediaqueri.es

Page 29: Adaptive Layouts - standards>next London 28.05.2011

http://mediaqueri.es

Page 30: Adaptive Layouts - standards>next London 28.05.2011

http://mediaqueri.es

Page 31: Adaptive Layouts - standards>next London 28.05.2011

www.themaninblue.com/writing/perspective/2004/09/21

Page 32: Adaptive Layouts - standards>next London 28.05.2011

“not a magic bullet...”

Page 33: Adaptive Layouts - standards>next London 28.05.2011

viewport meta

Page 34: Adaptive Layouts - standards>next London 28.05.2011

physical vs virtual pixels

Page 35: Adaptive Layouts - standards>next London 28.05.2011
Page 36: Adaptive Layouts - standards>next London 28.05.2011

mobile devices lie(to better serve the user)

Page 37: Adaptive Layouts - standards>next London 28.05.2011
Page 38: Adaptive Layouts - standards>next London 28.05.2011
Page 39: Adaptive Layouts - standards>next London 28.05.2011
Page 40: Adaptive Layouts - standards>next London 28.05.2011

viewport metasuggests sizing to mobile browser

Page 41: Adaptive Layouts - standards>next London 28.05.2011

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

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

Page 42: Adaptive Layouts - standards>next London 28.05.2011

Viewport properties

width initial-scaleheight minimum-scaleuser-scalable maximum-scale

Page 43: Adaptive Layouts - standards>next London 28.05.2011

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

Page 44: Adaptive Layouts - standards>next London 28.05.2011
Page 45: Adaptive Layouts - standards>next London 28.05.2011
Page 46: Adaptive Layouts - standards>next London 28.05.2011

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

Page 47: Adaptive Layouts - standards>next London 28.05.2011

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

Page 48: Adaptive Layouts - standards>next London 28.05.2011

<meta name="viewport" content="width=550, maximum-scale=1.0">

Page 49: Adaptive Layouts - standards>next London 28.05.2011

maximum-scale=1.0breaks zooming!

Page 50: Adaptive Layouts - standards>next London 28.05.2011

if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) { var viewportmeta = document.querySelector('meta[name="viewport"]'); if (viewportmeta) { viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0'; document.body.addEventListener('gesturestart', function() { viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6'; }, false); }}

adactio.com/journal/4470

Page 51: Adaptive Layouts - standards>next London 28.05.2011

device-width to the rescue?

Page 52: Adaptive Layouts - standards>next London 28.05.2011
Page 53: Adaptive Layouts - standards>next London 28.05.2011

in Mobile Safari only: device-width always same (portrait/landscape) … WTF?

Page 54: Adaptive Layouts - standards>next London 28.05.2011

high-dpi devices lieabout device-width

Page 55: Adaptive Layouts - standards>next London 28.05.2011
Page 56: Adaptive Layouts - standards>next London 28.05.2011

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

Page 57: Adaptive Layouts - standards>next London 28.05.2011
Page 58: Adaptive Layouts - standards>next London 28.05.2011

480px / 160% = 300px

Page 59: Adaptive Layouts - standards>next London 28.05.2011

<meta name="viewport" content="width=device-width, target-densitydpi=device-dpi">

Page 60: Adaptive Layouts - standards>next London 28.05.2011

CSS Device Adaptation@viewport { width: 320px; zoom: 2.3; user-zoom: fixed;}

dev.w3.org/csswg/css-device-adapt

Currently only in Opera Mobile 11 with -o- prefix dev.opera.com/articles/view/an-introduction-to-meta-viewport-and-viewport

Page 61: Adaptive Layouts - standards>next London 28.05.2011

Viewport properties

width / min-width / max-width user-zoom

height / min-height / max-height orientation

zoom / min-zoom / max-zoom

Page 62: Adaptive Layouts - standards>next London 28.05.2011

@media + @viewport@media screen and (max-device-width: 550px) { @-o-viewport { width: 550px; }}

only apply viewport width fixing on small-screen devices

Page 63: Adaptive Layouts - standards>next London 28.05.2011

@viewport@-o-viewport { width: 550px auto;}

minimum and maximum width

Page 64: Adaptive Layouts - standards>next London 28.05.2011

BUG ALERT: Opera currently not re-running Media Queries on portrait/landscape switch