"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Using Responsive Design in the Mobile Web
1. Using Responsive Design in the Mobile Web
HTML5DevConf
Chris Perkins - Intel
Intel Confidential — Do Not Forward
2. 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
3. 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
4. @media queries
4
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, …
5. Retina Images
5
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”>
6. 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)
7. layout
7
@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
8. 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)
9. layout
9
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
10. javascript & @media
10
-
window.matchMedia(‘(max-width: 400px)’)
{
– media: {String},
– matches:{Boolean},
– removeListener:{Function},
– addListener:{Function} }
‘(max-width:400px) and
(orientation:landscape)’ etc. OK
But no @media
11. 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.
12. Vertical sizing
12
-
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.
Introduce Self: Chris Perkins. Work for Intel, on Intel XDK
Have developed tools for developers or designers, including SiteGrinder, PhotoWebber and others
Comment on slide.
I cannot begin to cover, much less enumerate, all the choices, possible solutions, in an hour. Instead, going to focus on just one corner: Responsive Design.
IMPORTANT: If you are developing for the mobile web, you need to be aware of the world your app will live in when on the phone. Not the world it is in while on your desktop.
You get your app into the App Stores, and the first user to download it will likely have an older Android or iOS install and it’s built-in system webview is old and fragile. It wasn’t current when the phone was released, much less now. All your hard-earned mad-latest CSS skillz wither when facing these impassive bricks. The user cannot update that webview by simply updating their browser app on the phone. They must upgrade the underlying OS, and for many phones the manufacturer or carrier has either forgotten or prevented them from doing so.
It was trendy a few years ago to distinguish Responsive Design from Adaptive Design. But, honestly, everyone is so tired these days no one cares. Excepting possibly some few pedants.
NOTE: vh coordinates buggy on iOS. And vw, vh unsupported before Android 4.4 (except crosswalk).
color-change demo
Any CSS Property can be used. Float, font-size,
NOTE: Media Queries are well supported. Everywhere but IE8.
Retina-image demo
Obviously, can be combined with and (min-width:400px) etc
Will both images be loaded?
Hey, since this is the Mobile Web and if you don’t care about browsers, don’t even bother with the rest of my talk.
Layout demo
Body margin:0 -- full bleed. Easier calculation.
Min-width:250 means less thinking. All the media queries are expressed in multiples of that minimum width.
We will use actual “width” in the media queries themselves.
Margin:0 very important. Much much harder to think about with real margins. Use nested containers if you need real margins.
Box-sizing:border-box. In this demo I’m using light blue borders as fake margins. This stunt will only work with box-sizing:border-box. Otherwise we are back to thinking again.
Everything from the previous slide is well trodden ground. Many have come before and have simplified it with tools and libraries.
Layout-flexbox demo. Use Chrome “Live Layout” mode
It has been said that flexbox is finally CSS layout done right, and that it is an embarrassment that it has taken
Much simpler. Just works. Note that we didn’t even need a media query in this example.
(Note we might want @media (max-width:400px){ .container { flex-direction:column } } )
In my experience, this actually works pretty well across a wide variety of platforms. Recommend testing and planning for testing.
Phone updates can’t be counted on. (w/ exception of Crosswalk)
Notes:
No ‘@media’ part.
Very handy. Important
redirect project demo
For true web apps (served) the story may be different. Sessions/Cookies
Phone versus Tablet is generally safe, because use can’t “change” their device by flipping it over or shaking it.
Note: best to use _both_ check-at-start and listen-for-change .