using responsive design in the mobile web

14
Intel Confidential — Do Not Forward Using Responsive Design in the Mobile Web HTML5DevConf Chris Perkins - Intel

Upload: intel-software

Post on 05-Aug-2015

127 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Using Responsive Design in the Mobile Web

Intel Confidential — Do Not Forward

Using Responsive Design in the Mobile WebHTML5DevConf

Chris Perkins - Intel

Page 2: Using Responsive Design in the Mobile Web

2

Introductory Equations

Someone told me that each equation I included in the book would halve the sales – Stephen Hawking

Speaker = Chris Perkins

Layout + Mobile Web = Challenging

Design Choices x Technologies x Libraries x Devices > Number.MAX_VALUE

Page 3: Using Responsive Design in the Mobile Web

3

Responsive Design

Power has to be insecure to be responsive – Ralph Nader

Designing a layout that works on a variety of screen sizes, orientations, and devices. The design responds to its environment.

vs. Adaptive Design

Includes

@media queries

%, em (vw & vh) coordinates

redirects

javascript

Page 4: Using Responsive Design in the Mobile Web

4

Click icon to add picture

@media queries

The Basics

@media

min-width: / max-width

orientation: landscape / portrait

and https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

device-width, aspect-ratio, etc.

only, not

print, screen, handheld, all, …

Page 5: Using Responsive Design in the Mobile Web

5

Click icon to add picture

Retina Images

background-image css property

Q: what about <img> tag? A: Use JS. Google “retina <img>”

<img src=“little_baby.jpg” data-src2x=“big_baby.jpg”>

Page 6: Using Responsive Design in the Mobile Web

6

Landscape / Portrait Only

You don’t change the course of history by turning the faces of portraits to the wall – Jawaharlal Nehru

Cordova config.xml (for Cordova CLI or PhoneGapBuild)

<preference name="orientation" value="portrait" />

Intel XDK

Projects Pane Settings (once for each desired platform)

Only for Builds (not Emulator or Previewing)

Page 7: Using Responsive Design in the Mobile Web

7

Click icon to add picture

layout

@media & float

Floating boxes float:left

min-width:250px

margin:0px

box-sizing:border-box

@media queries set width 25% for 1000px or greater

– 4 x 250 = 1000

33% for 750 – 1000– 3 x 250 = 750

Page 8: Using Responsive Design in the Mobile Web

8

@media & float : Frameworks and Tools

-

Grid Systems

Zurb Foundation (foundation.zurb.com)

Twitter Bootstrap

960.gs

Many others

Tools

Adobe Edge Reflow

Intel XDK (App Designer)

Page 9: Using Responsive Design in the Mobile Web

9

Click icon to add picture

layout

flexbox Much Simpler.

Just works.

Supposedly less well supported– Android 4.3 and earlier use “old” spec.

– May require –webkit prefix– Crosswalk OK

– IE 11 OK. IE 10 uses 2012 spec.– http://caniuse.com/#search=flexbox

Page 10: Using Responsive Design in the Mobile Web

10

Click icon to add picture

javascript & @media

- window.matchMedia(‘(max-width:

400px)’)

{ – media: {String}, – matches:{Boolean}, – removeListener:{Function}, – addListener:{Function} }

‘(max-width:400px) and (orientation:landscape)’ etc. OK

But no @media

Page 11: Using Responsive Design in the Mobile Web

11

redirect

JavaScript is only redirect solution for Cordova/PhoneGap apps

Issues

A full “restart” of app– At start: palatable– While running: difficult

– OK for phone versus tablet. – But bad choice for portrait vs. landscape.

Burden of transferring application state – via localStorage etc

deviceready

Summary: Single Page App is still your best friend.

Page 12: Using Responsive Design in the Mobile Web

12

Click icon to add picture

Vertical sizing

- Sizing of element vs text

vh, vmax/vmin not backward compatible on Android

em & rem

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

– Not well supported.– Tricky.

@viewport ?– Draft. Unsupported.

Page 14: Using Responsive Design in the Mobile Web

Intel Confidential — Do Not Forward