responsive websites. toolbox

Post on 15-Jan-2015

3.429 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

A talk given at Appspirina workshop on March 29th, 2012 organized by http://mobiledeveloper.pl/. Event page: https://www.facebook.com/events/296799847060237/

TRANSCRIPT

Responsive websites.Toolbox

WARSAW, 29.03.2012

@appsp i r i na

Agenda

• Feature detection

• Media Queries 101

• Viewport Tricks

• Performance

• CSS frameworks

• Responsive images

• Micro libraries

• jQuery plugins

• Mobile Wordpress

• Browser testing

PROGRESSIVEenhancement

PIXELperfection

vs

Source: Justin Avery (CC BY-SA 3.0)

Interfaces don’t have to look the same everywhere.

TV already solved this problem.

We knowfeatures:

✦ screen size

✦ local storage

✦ touch

✦ canvas

✦ SVG

✦ screen size

✦ no touch

✦ poor JavaScript

✦ no canvas

✦ isMSIE

Hat tip: Yiibu

There areconstraints:

Feature detect

<link rel="stylesheet" media="screen, projection" href="normal.css"> <link rel="stylesheet" media="print" href="print.css">

Party like it’s 1998!

CSS2 media types

CSS3 Media Queries

<link rel="stylesheet" type="text/css" href="example.css" media="screen and (color)">

Media type Expression

Better CSS3 Media Queries

@media screen and (color) { body { background: #f00; }}

@import url("example.css") screen and (color);

Increase maintainability with @import:

Save HTTP requests:

✦ former updates on orientation change, latter doesn’t

✦ only max/min-width will be visible in desktop browser

!"#/!$%-width or-device-width?

Detect high DPI screens

<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="highdpi.css" />

Just retina display:

Detect high DPI screens

@mediaonly screen and (-webkit-min-device-pixel-ratio: 1.5),only screen and (-o-min-device-pixel-ratio: 3/2),only screen and (min--moz-device-pixel-ratio: 1.5),only screen and (min-device-pixel-ratio: 1.5) { /* Styles */}

Saves HTTP request, non-iOS-specific:

Detect iPad orientation

<link rel="stylesheet" media="all and (orientation: portrait)" href="portrait.css">

<link rel="stylesheet" media="all and (orientation: landscape)" href="landscape.css">

Browser support

— caniuse.com

Need supportfor IE6-8?

respond.jshttps://github.com/scottjehl/Respond

Viewport demystified

<meta name="viewport" content="width=device-width, initial-scale=1.0">

width=500 Custom width setting

minimum-scale=1.0 Prevents from zooming out

maximum-scale=1.0 Prevents from zooming in. Useful with forms

user-scalable=no Use cautiously. Mostly for mobile-specific designs

Hey girl,

when I see you,

my iPhone

gets 2x initial zoom

Home screen icon

<link rel="apple-touch-icon" href="apple-touch-icon.png">

supported by Android 2.1+, too!

Home screen icon

iOS adds by default:

• Rounded corners

• Drop shadow

• Reflective shine

<link rel="apple-touch-icon-precomposed"

href="apple-touch-icon-precomposed.png">

prevents addition of iOS effects

Home screen icon

Complete snippet:

http://mathiasbynens.be/notes/touch-icons

144 × 144

114 × 114

72 × 72

iPad ‘Retina’ display

iPhone ‘Retina’ display

iPad, iPad 2

57 × 57 non-Retina iOS and others

Hiding address bar

<meta name="apple-mobile-web-app-capable" content="yes">

After adding as a bookmark:

Cross-browser solution:

https://github.com/scottjehl/Hide-Address-Bar

iOS viewport scaling bug

Portrait Landscape

iOS viewport scaling bug

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); }}

— http://adactio.com/journal/4470/

fix

Mobile first, stupid!

Decrease dependencies

The Boston Globe used the following methodology:

Load resources conditionally

ASSETSdepend on

screendimensions

DESIGNdepends on

windowdimensions

Use CSS Data URL generators

or… built-in editor tools (e.g. implemented in Sublime)

Develop your own!

Starbucks style guide: http://www.starbucks.com/static/reference/styleguide/

max-width: 100%;

Doesn’t provide resources optimization

Defined as obsolete in HTML5

Needs 2 http requests

lowsrc

Uses up the most resources

Standard JavaScriptreplacement

Relies on JS for displaying content. Poor idea.

1pxgif

da t a - h i ghs rc

developed by Filament Group

used on Boston Globe

✦ PHP solution

✦ quick to set up

✦ doesn’t work with CDNs

Adaptive-images.com by Matt Wilcox

✦ Twenty ten fully responsiveequivalent available

✦ List of responsive themesat Free Themes Directory grows constantly

✦ Lots of responsive premium themes on Forest, WooThemes and Themify

2. Responsive themes

http://responsivetwentyten.com/

✦ Mobble

✦ Dropdown Menus

✦ WP Fluid Images

4. Responsive design helpers

if (is_mobile()) { echo "Dude, you rock."}

There are EMULATORS

to solve your

PROBLEMS38*

99

* http://www.mobilexweb.com/emulators

Testing onREALDEVICESis crucial.

✦ Analyze your website’s traffic

✦ Review the local platform landscape

✦ Check against device-specific factors (form, screen size, performance, DPI)

✦ Compare with project-specific factors (location-based?)

Building your pool of devices

— Stephanie Rieger,http://stephanierieger.com/strategies-for-choosing-test-devices/

Q & A

Wojtek Zając (@theanxy)http://www.slideshare.net/wojciechzajac This work is licensed

under a Creative Commons Attribution 3.0 Unported License

Thanks!

Based on the brilliant research and works by:

• Scott Jehl

• Patrick H. Lauke

• Russ Weakley

& others.

First slide photo: http://www.flickr.com/photos/johnmcnab/5758738799/

Stephanie Rieger: http://www.flickr.com/photos/29022619@N03/6116794697/

Credit where it’s due

• Matt Wilcox

• Brad Frost

• Rachel McCollin

• Yiibu.com

top related