Slide 1

Slide 1 text

Cross-Device Development with Web Standards Tomomi Imura flickr.com/photos/64855052@N00/3967578543/ by Yoichi Nakanishi b

Slide 2

Slide 2 text

H E L L O M Y N A M E I S Tomomi @girlie_mac 02

Slide 3

Slide 3 text

One Web Approach Mobile Web Best Practices by W3C (2008) One Web means making, as far as is reasonable, the same information and services available to users irrespective of the device they are using. ” “ Mobile Web Best Practices 1.0 (2008) 03

Slide 4

Slide 4 text

Form Factors · Screen Sizes

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Adaptive Design 07

Slide 8

Slide 8 text

Adaptive Design 1. Progressive Enhancement • Enhancing Experiences based on browser capabilities • Graceful Degradation - Fallbacks 2. Responsive Design • Fluid Layout • Media Queries • Responsive Images 08

Slide 9

Slide 9 text

Fluid Layout Neue flickr.com/photos/meantux/378103724/ by Denis-Carl Robidoux bn

Slide 10

Slide 10 text

Then • HTML Table Layout (Party like it's 1999) • The CSS "Holy Grail" Column Liquid Layout • Float • Negative margin • All the hacks that are PITA • UI Frameworks for Grid Layout • YUI • jQuery Masonry 10

Slide 11

Slide 11 text

Now and Future: CSS3 Layouts • Columns • Flexible Box ("FlexBox") • Regions • Grids 11

Slide 12

Slide 12 text

Fluid Columns Demo on JSFiddle 12

Slide 13

Slide 13 text

CSS Multi-column Layout Module . c o l { - w e b k i t - c o l u m n s : 2 0 0 p x ; - m o z - c o l u m n s : 2 0 0 p x ; c o l u m n s : 2 0 0 p x ; / * c o l u m n - c o u n t : a u t o * / } Browser Support: * 2.1* 3* 7* * 10 11.5p 15Bl* http://www.w3.org/TR/css3-multicol/ 13

Slide 14

Slide 14 text

Flexbox Layout with MQ Demo on JSFiddle 14

Slide 15

Slide 15 text

CSS Flexible Box Layout Module # m a i n { d i s p l a y : f l e x ; f l e x - f l o w : r o w ; } . . . @ m e d i a a l l a n d ( m a x - w i d t h : 6 4 0 p x ) { # m a i n { f l e x - f l o w : c o l u m n ; } } Latest syntax: 21* 7* 10* 11 12p 15Bl http://www.w3.org/TR/css3-flexbox/ 15

Slide 16

Slide 16 text

Responsive Regions Layout Demo on Codepen: http://cdpn.io/LbAFq 16

Slide 17

Slide 17 text

CSS Regions Module A 1 2 3 4 http://dev.w3.org/csswg/css-regions/ 17

Slide 18

Slide 18 text

Responsive Regions Layout < d i v c l a s s = " r e g i o n r e g i o n 1 " > < / d i v > < d i v c l a s s = " r e g i o n r e g i o n 2 " > < / d i v > . . . < a r t i c l e c l a s s = " c o n t e n t " > c o n t e n t h e r e . . . < / a r t i c l e > . c o n t e n t { f l o w - i n t o : a r t i c l e ; } . r e g i o n { f l o w - f r o m : a r t i c l e ; } @ m e d i a s c r e e n a n d ( m a x - w i d t h : 4 0 0 p x ) { . c o n t e n t { f l o w - i n t o : n o n e ; } . r e g i o n { d i s p l a y : n o n e ; } } 7* 10* IE10 requires iframe 18

Slide 19

Slide 19 text

Responsive Grid An arrangement suitable for ‘portrait’ orientation. An arrangement suitable for ‘landscape’ orientation. 10* http://www.w3.org/TR/css3-grid-layout/ 19

Slide 20

Slide 20 text

Media-Queries http://commons.wikimedia.org/wiki/File:Metric_Volume_Measuring_Vessels_Frontsides-In_use.jpg ba

Slide 21

Slide 21 text

CSS2.1 @media Media-Types For mobile phones: @ m e d i a h a n d h e l d { / * S o m e m o b i l e - s p e c i f i c C S S h e r e * / } Only supported by: • Opera Mini • OpenWave • Obigo • PIE (partial) 21

Slide 22

Slide 22 text

CSS3: Media-Queries allows content rendering to adapt to conditions: • width of the target viewport • width of the device's screen size • screen orientations (landscape v. portrait) • device pixel ratio (aka. Retina) etc... 22

Slide 23

Slide 23 text

CSS3: Media-Queries Separate styles by the width of the target viewport (browser display area) @ m e d i a o n l y s c r e e n a n d ( m i n - w i d t h : 7 6 8 p x ) a n d ( m a x - w i d t h : 1 0 2 4 p x ) { / * S t y l e s * / } 23

Slide 24

Slide 24 text

CSS3: Media-Queries by device-width, the width of the device's screen size @ m e d i a o n l y s c r e e n a n d ( m i n - d e v i c e - w i d t h : 3 2 0 p x ) a n d ( m a x - d e v i c e - w i d t h : 4 8 0 p x ) { / * S t y l e s * / } 24

Slide 25

Slide 25 text

CSS3: Media-Queries combined with screen orientations @ m e d i a o n l y s c r e e n a n d ( m i n - d e v i c e - w i d t h : 7 6 8 p x ) a n d ( m a x - d e v i c e - w i d t h : 1 0 2 4 p x ) a n d ( o r i e n t a t i o n : l a n d s c a p e ) { / * S t y l e s * / } . . . 25

Slide 26

Slide 26 text

CSS3: Media-Queries CSS3, Hell Yeah! @ m e d i a o n l y s c r e e n a n d ( m a x - w i d t h : c a l c ( 7 6 8 p x - 2 e m ) ) { / * S t y l e s * / } . . . 26

Slide 27

Slide 27 text

CSS3: Media-Queries separate styles by device pixel ratio 27

Slide 28

Slide 28 text

High Pixel Density Displays

Slide 29

Slide 29 text

The High DPI https://www.webkit.org/blog/55/high-dpi-web-sites/ 29

Slide 30

Slide 30 text

30

Slide 31

Slide 31 text

31

Slide 32

Slide 32 text

32

Slide 33

Slide 33 text

33

Slide 34

Slide 34 text

34

Slide 35

Slide 35 text

CSS Pixel vs. Device Pixel • Pixel in CSS is relative • 1 CSS pixel != 1 device pixel 35

Slide 36

Slide 36 text

Pixel Density in DOM w i n d o w . d e v i c e P i x e l R a t i o Device Browser Pixel Density Nexus One Android browser 1.5 Galaxy Nexus Chrome 2.0 Galaxy Nexus Opera Mobile 2.25 Samsung Galaxy S4 Chrome 3.0 36

Slide 37

Slide 37 text

Zoom Dependent Pixel Density ⌘+ and ⌘- , but not for pinch-zoom Test page (Firefox and Chrome 31+) 37

Slide 38

Slide 38 text

Media-Queries for "Retina" @ m e d i a o n l y s c r e e n a n d ( m i n - d e v i c e - p i x e l - r a t i o : 2 ) { / * s t y l e s f o r h i - D P I s c r e e n s * / } 38

Slide 39

Slide 39 text

WTF Vendor Prefix! @ m e d i a o n l y s c r e e n a n d ( - w e b k i t - m i n - d e v i c e - p i x e l - r a t i o : 1 . 5 ) { . . . } @ m e d i a o n l y s c r e e n a n d ( m i n - - m o z - d e v i c e - p i x e l - r a t i o : 1 . 5 ) { . . . } @ m e d i a o n l y s c r e e n a n d ( - o - m i n - d e v i c e - p i x e l - r a t i o : 3 / 2 ) { . . . } 39

Slide 40

Slide 40 text

Unprefix: resolution MQ @ m e d i a ( - w e b k i t - m i n - d e v i c e - p i x e l - r a t i o : 2 ) , ( m i n - r e s o l u t i o n : 1 9 2 d p i ) { . . . } Typical Browser: 96dpi (96 CSS-pixel in 1 CSS-inch) 40

Slide 41

Slide 41 text

...even easier @ m e d i a ( - w e b k i t - m i n - d e v i c e - p i x e l - r a t i o : 2 ) , ( m i n - r e s o l u t i o n : 2 d p p x ) { . . . } 29 16 41

Slide 42

Slide 42 text

CSSOM View Module: matchMedia() approaching media-queries in DOM v a r m q l = w i n d o w . m a t c h M e d i a ( m e d i a Q u e r y S t r i n g ) ; Browser Support: 9 3 5 10 6 10 12.1p 15Bl http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface 42

Slide 43

Slide 43 text

v a r m q l = w i n d o w . m a t c h M e d i a ( ' ( o r i e n t a t i o n : l a n d s c a p e ) ' ) ; i f ( m q l . m a t c h e s ) { / * t h e c u r r e n t o r i e n t a t i o n i s i n l a n d s c a p e * / } e l s e { / * p o r t r a i t * / } 43

Slide 44

Slide 44 text

CSS Device Adaptation < m e t a n a m e = " v i e w p o r t " c o n t e n t = " w i d t h = d e v i c e - w i d t h " > ↓ CSS @ v i e w p o r t { w i d t h : d e v i c e - w i d t h ; } 44

Slide 45

Slide 45 text

CSS Device Adaptation @ - o - v i e w p o r t { w i d t h : d e v i c e - w i d t h } @ - m s - v i e w p o r t { w i d t h : d e v i c e - w i d t h } * @ v i e w p o r t { w i d t h : d e v i c e - w i d t h } 11P 10 * bug in IE10 - reports in device pixel value 45

Slide 46

Slide 46 text

@viewport in @media @ m e d i a s c r e e n a n d ( o r i e n t a t i o n : p o r t r a i t ) { @ v i e w p o r t { w i d t h : 7 6 8 p x ; h e i g h t : 1 0 2 4 p x ; } / * C S S f o r p o r t r a i t l a y o u t g o e s h e r e * / } 46

Slide 47

Slide 47 text

Media Queries Level 4 • "pointer" - accuracy of a pointing device. • n o n e • c o a r s e aka "fat finger" • f i n e • "hover" • 0 • 1 http://dev.w3.org/csswg/mediaqueries4/#pointer 47

Slide 48

Slide 48 text

Media Queries Level 4 @ m e d i a ( h o v e r ) { . m e n u l i : h o v e r { b a c k g r o u n d - c o l o r : # b a d a 5 5 ; } } 48

Slide 49

Slide 49 text

MQ L4: Range Features @ m e d i a ( m i n - h e i g h t : 6 0 0 p x ) { . . . } ↓ @ m e d i a ( h e i g h t > = 6 0 0 p x ) { . . . } http://dev.w3.org/csswg/mediaqueries/#mq-range-context 49

Slide 50

Slide 50 text

MQ L4: Luminosity @ m e d i a ( l u m i n o s i t y : n o r m a l ) { b o d y { b a c k g r o u n d - c o l o r : # d d d ; c o l o r : # 0 0 0 ; } } @ m e d i a ( l u m i n o s i t y : d i m ) { b o d y { b a c k g r o u n d - c o l o r : # 4 4 4 ; c o l o r : # f f f ; } } @ m e d i a ( l u m i n o s i t y : w a s h e d ) { b o d y { b a c k g r o u n d - c o l o r : # f f f ; c o l o r : # 3 3 3 ; } } http://dev.w3.org/csswg/mediaqueries4/#luminosity 50

Slide 51

Slide 51 text

DOM Ambient Light Events Demo Video Link: https://vimeo.com/79466285 • Codepen Demo: http://cdpn.io/pvmBs 0:22 51

Slide 52

Slide 52 text

Responsive Images flickr.com/photos/joaomoura/2348271655/ bna

Slide 53

Slide 53 text

Responsive Images Use Cases 1. Resolution switching 2. Art Direction 3. DPR Switching (High-Res images) 53

Slide 54

Slide 54 text

Resolution switching 54

Slide 55

Slide 55 text

Art-Direction instead of simple scaling 55

Slide 56

Slide 56 text

DPR Switching: High-Res Images 1x 2x 56

Slide 57

Slide 57 text

Currently used methods and problems 57

Slide 58

Slide 58 text

Using Media-Queries @ m e d i a o n l y s c r e e n a n d ( m i n - d e v i c e - w i d t h : 7 6 8 p x ) a n d ( m a x - d e v i c e - w i d t h : 1 0 2 4 p x ) { b a c k g r o u n d - i m a g e : u r l ( c a t - t a b l e t . j p g ) ; w i d t h : 6 4 0 p x ; h e i g h t : 3 2 0 p x ; } @ m e d i a o n l y s c r e e n a n d ( m i n - w i d t h : 1 2 2 4 p x ) { b a c k g r o u n d - i m a g e : u r l ( c a t - d e s k t o p . j p g ) ; . . . } 58

Slide 59

Slide 59 text

Yay • Easy enough. No scripts. Meh • Hard to figure out MQ Breakpoint • Not semantic to use b a c k g r o u n d for contents • Some browsers download all assets (Tests by Tim Kadlec) 59

Slide 60

Slide 60 text

Fluid Resizing an Image 60

Slide 61

Slide 61 text

Fluid Resizing an Image Shrink and Stretch without MQ < i m g s r c = " i m a g e s / r e l a t i v e l y - l a r g e - p h o t o . j p g " a l t = " c a t " > i m g { w i d t h : 1 0 0 % ; h e i g h t : a u t o ; } 61

Slide 62

Slide 62 text

Yay • Only one asset • Easy to implement. No MQ breakpoints needed. Meh • CPU intensive • Westing bandwidth 62

Slide 63

Slide 63 text

Art Direction: Cropping with CSS https://dl.dropboxusercontent.com/u/1330446/tests/clip.html 63

Slide 64

Slide 64 text

CSS2 Clip Property < d i v c l a s s = " i m a g e - c o n t a i n e r " > < i m g s r c = " i m a g e s / s u s h i - l a r g e . j p g " > < / d i v > . i m a g e - c o n t a i n e r { p o s i t i o n : r e l a t i v e ; } . i m a g e - c o n t a i n e r i m g { p o s i t i o n : a b s o l u t e ; } @ m e d i a o n l y s c r e e n a n d ( m a x - w i d t h : 4 8 0 p x ) { . i m a g e - c o n t a i n e r i m g { c l i p : r e c t ( 8 0 p x 2 7 0 p x 2 7 0 p x 2 4 0 p x ) ; / / B L E H ! ! ! } } 64

Slide 65

Slide 65 text

CSS2 Clip Property p o s i t i o n : a b s o l u t e ; c l i p : r e c t ( t o p r i g h t b o t t o m l e f t ) ; Photo: http://www.flickr.com/photos/nicolelee/1798352472/ by Nicole Lee bna 65

Slide 66

Slide 66 text

Yay • Only one asset Meh • CSS clip is cumbersome • Westing bandwidth 66

Slide 67

Slide 67 text

Up-Res for Hi-DPI Screens 67

Slide 68

Slide 68 text

Up-Res Images with MQ . b a n n e r { b a c k g r o u n d - i m a g e : u r l ( b a n n e r . p n g ) ; w i d t h : 3 2 0 p x ; h e i g h t : 1 6 0 p x ; } @ m e d i a ( - w e b k i t - m i n - d e v i c e - p i x e l - r a t i o : 2 ) , ( m i n - r e s o l u t i o n : 2 d p p x ) { . b a n n e r { b a c k g r o u n d - i m a g e : u r l ( b a n n e r - 2 x . p n g ) ; b a c k g r o u n d - s i z e : 1 0 0 % ; } } 68

Slide 69

Slide 69 text

Yay • Simple enough to implement Meh • Browser-dependent MQ data types / prefix • Not semantic to use b a c k g r o u n d for contents • Some browsers download all assets (Tests by Tim Kadlec) 69

Slide 70

Slide 70 text

Up-Res with CSS image-set() < d i v i d = " p h o t o 0 1 " > < / d i v > # p h o t o 0 1 { w i d t h : 3 0 0 p x ; h e i g h t : 2 0 0 p x ; b a c k g r o u n d - i m a g e : u r l ( i m a g e s / l o w r e s . j p g ) ; b a c k g r o u n d - i m a g e : - w e b k i t - i m a g e - s e t ( u r l ( i m a g e s / l o w r e s . j p g ) 1 x , u r l ( i m a g e s / h i r e s . j p g ) 2 x ) ; } 6* 19* 15bl* CSS Image Values and Replaced Content Module Level 4 70

Slide 71

Slide 71 text

Yay • Less hassle syntax Meh • Not enough browser supports. Spec is unstable. • Not semantic to use b a c k g r o u n d for contents 71

Slide 72

Slide 72 text

Vector Graphics FTW! 72

Slide 73

Slide 73 text

SVG < i m g s r c = " l o g o . s v g " w i d t h = "4 3 2 " > 73

Slide 74

Slide 74 text

Web Font Icons 36px 72px 108px 144px 288px      IcoMoon 74

Slide 75

Slide 75 text

Web Font Icons < s p a n d a t a - i c o n = " & # x e 0 0 0 ; " > f o r k m e < / s p a n > @ f o n t - f a c e { f o n t - f a m i l y : ' i c o n s ' ; s r c : u r l ( ' f o n t s / i c o n s . w o f f ' ) f o r m a t ( ' w o f f ' ) ; } [ d a t a - i c o n ] : : b e f o r e { f o n t - f a m i l y : ' i c o n s ' ; c o n t e n t : a t t r ( d a t a - i c o n ) ; f o n t - s i z e : 7 2 p x ; } 75

Slide 76

Slide 76 text

Other Solutions • Javascript • Mobify.js etc. • Polyfills (Picturefill.js, x-picture/Polymer) • Server-side • "Adaptive Images" (PHP) • Sencha.io Src (UA lookup in Cloud) • Creative Hacks • Clown Car Technique 76

Slide 77

Slide 77 text

Responsive ? 77

Slide 78

Slide 78 text

O NOES! was not made for the responsive design! 78

Slide 79

Slide 79 text

We need a standard solution. ... or a few. 79

Slide 80

Slide 80 text

The srcset attribute Proposal by Apple & adopted by WhatWG < i m g a l t = " T h e B r e a k f a s t C o m b o " s r c = " b a n n e r . j p e g " s r c s e t = " b a n n e r - H D . j p e g 2 x , b a n n e r - p h o n e . j p e g 1 0 0 w , b a n n e r - p h o n e - H D . j p e g 1 0 0 w 2 x " > WebKit Nightly r154002 The srcset attribute - An HTML extension for adaptive images 80

Slide 81

Slide 81 text

Picture Element Proposal RespImg CG < p i c t u r e w i d t h = " 5 0 0 " h e i g h t = " 5 0 0 " > < s o u r c e m e d i a = " ( m i n - w i d t h : 4 5 e m ) " s r c = " l a r g e . j p g " > < s o u r c e m e d i a = " ( m i n - w i d t h : 1 8 e m ) " s r c = " m e d . j p g " > < s o u r c e s r c = " s m a l l . j p g " > < i m g s r c = " f a l l b a c k . j p g " > < p > A c c e s s i b l e t e x t < / p > < / p i c t u r e > Responsive Images Community Group 81

Slide 82

Slide 82 text

HTTP Client-Hints Proposal from Google: let the server selects the right asset [ R e q u e s t ] G E T / k i t t e n . j p g H T T P / 1 . 1 U s e r - A g e n t : . . . A c c e p t : i m a g e / w e b p , i m a g e / j p g C H : d p r = 2 . 0 http://www.igvita.com/2013/08/29/automating-dpr-switching-with-client-hints/ 82

Slide 83

Slide 83 text

What's Next? http://www.flickr.com/photos/barbostick/3581760713/ ba

Slide 84

Slide 84 text

Smart TV W3C: Web and TV Interest Group Panasonic Viera Smart TV 84

Slide 85

Slide 85 text

Automotive proposals for standardizing HTML5-based vehicle APIs: • Tizen • Webinos • GENIVI • QNX W3C: Automotive and Web Platform Business Group QNX Auto Blog 85

Slide 86

Slide 86 text

Wearable Devices & IoT http://imgur.com/g/memes/qKH2tM8 86

Slide 87

Slide 87 text

Thank you! Tomomi Imura • @girlie_mac • girliemac.com • github.com/girliemac • speakerdeck.com/girlie_mac Slide: http://girliemac.github.io/presentation-slides/html5-mobile- approach/rwd.html 87

Slide 88

Slide 88 text

88