+ All Categories
Transcript
Page 1: Responsive Web Design - Web & PHP Conference - 2013-09-18

Responsive Web Design

Frédéric HarperSenior Technical Evangelist @ Mozilla@fharper | outofcomfortzone.net

2013-0

9-1

8

Page 2: Responsive Web Design - Web & PHP Conference - 2013-09-18

Questions

http://wpc13.cnf.io/sessions/129

Page 3: Responsive Web Design - Web & PHP Conference - 2013-09-18

How we view the web today…• The Desktop Browser• Mobile Browsers• Tablet form-factors• Televisions• Game Consoles• More…• So what’s the problem?

Page 4: Responsive Web Design - Web & PHP Conference - 2013-09-18

The Anti-Pattern

Page 5: Responsive Web Design - Web & PHP Conference - 2013-09-18

Responsive Web Designs

Page 6: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 7: Responsive Web Design - Web & PHP Conference - 2013-09-18

Responsive Web Design

• Thinking of the user’s needs instead of

ours.

• Adapt to various device capabilities instead

of configurations.

• Help future-proof our sites.

Page 8: Responsive Web Design - Web & PHP Conference - 2013-09-18

The way to go

Page 9: Responsive Web Design - Web & PHP Conference - 2013-09-18

Elements of Responsive Web Design• A flexible, grid-based layout,

• Flexible images and media,

• Media queries.

• Something else.

Page 10: Responsive Web Design - Web & PHP Conference - 2013-09-18

Flexible, Grid-based Layout

Page 11: Responsive Web Design - Web & PHP Conference - 2013-09-18

Ok, so what’s the problem?

• Non-responsive sites are no fun.

• Fixed-width sites are not the best experiences.

• Design tools tend to use pixels.

• Sometimes a pixel does not equal a pixel.

• So how do we turn pixels to their em counterparts?

Page 12: Responsive Web Design - Web & PHP Conference - 2013-09-18

𝚫 𝒚𝚫 𝒙

≈ 𝐥𝐢𝐦𝒏→∞ (𝟏+𝟏

𝒏 )𝒏

×−𝒃±√𝒃𝟐−𝟒𝒂𝒄

𝟐𝒂± 𝒇 (𝒙 )=𝒂𝟎+∑

𝒏=𝟏

(𝒂𝒏𝐜𝐨𝐬𝒏𝝅 𝒙𝑳

+𝒃𝒏𝐬𝐢𝐧𝒏𝝅 𝒙𝑳 )

Pixels to Ems Algorithm

Page 13: Responsive Web Design - Web & PHP Conference - 2013-09-18

target context result÷ ¿

Page 14: Responsive Web Design - Web & PHP Conference - 2013-09-18

target context result÷ ¿

h1 { font-size: 24px;}

24 / 16 = 1.5h1 { font-size: 1.5em;}

h1 a { font-size: 11px;}

11 / 24 = 0.458333333+

h1 a { font: 0.458333333+;}

32

Responsive Web Design READ MORE >>

1

em

%

Page 15: Responsive Web Design - Web & PHP Conference - 2013-09-18

And the Grid?#page { margin: 36px auto; width: 960px;}.blog { margin: 0 auto 53px; width: 900px;}.blog .main { float: left; width: 566px;}.blog .other { float:right; width: 331px;}

#page { margin: 36px auto; width: 90%;}.blog { margin: 0 auto 53px; width: 93.75%; /* 900/960 */}.blog .main { float: left; width: 62.88+%;}.blog .other { float:right; width: 36.77+%;}

.blog { width: 900/960;}.blog .main { width: 566/900;}.blog .other { width: 331/900;}

target context result÷ ¿

Page 16: Responsive Web Design - Web & PHP Conference - 2013-09-18

Flexible Images and Media

Page 17: Responsive Web Design - Web & PHP Conference - 2013-09-18

A Simple Solution

Works on images, as well as other media like <video>.

img { max-width: 100%;}

Page 18: Responsive Web Design - Web & PHP Conference - 2013-09-18

Another PossibilityFilament Group –

depends on cookies and JavaScript

Page 19: Responsive Web Design - Web & PHP Conference - 2013-09-18

Responsive images

Page 20: Responsive Web Design - Web & PHP Conference - 2013-09-18

Picture element, draft proposed

<picture> <source media="(min-width: 40em)" srcset="big.jpg 1x, big-hd.jpg 2x"> <source srcset="small.jpg 1x, small-hd.jpg 2x"> <img src="fallback.jpg" alt=""></picture>

Page 21: Responsive Web Design - Web & PHP Conference - 2013-09-18

srcset, draft proposed

<img src="fallback.jpg" alt="" srcset="small.jpg 640w 1x, small-hd.jpg 640w 2x, med.jpg 1x, med-hd.jpg 2x ">

Page 22: Responsive Web Design - Web & PHP Conference - 2013-09-18

Media Queries

Page 23: Responsive Web Design - Web & PHP Conference - 2013-09-18

Not so long ago…

• We could define media types: screen and print.

• But not easily respond to the user’s display.

• Lots of grunt work.

• Didn’t spend much time thinking about mobile

devices.

Page 24: Responsive Web Design - Web & PHP Conference - 2013-09-18

CSS3 Media Queries

The CSS3 Media Queries Module specifies

methods to enable web developers to scope

a style sheet to a set of precise device

capabilities.

Page 25: Responsive Web Design - Web & PHP Conference - 2013-09-18

Simple Example

@media screen and (max-width: 600px) { body { font-size: 80%; }}

Page 26: Responsive Web Design - Web & PHP Conference - 2013-09-18

Other Queries@media screen and (min-width:320px) and (max-width:480px)

@media not print and (max-width:600px)

@media screen (x) and (y), print (a) and (b)

Page 27: Responsive Web Design - Web & PHP Conference - 2013-09-18

Can be declared…In the StylesheetImport Rule

@import url(mq.css) only screen and (max-width:600px)

link Element

<link rel=“stylesheet” media=“only screen and (max-width:800px)” href=“mq.css”>

Page 28: Responsive Web Design - Web & PHP Conference - 2013-09-18

Supported Media Properties• min/max-width• min/max-height• device-width• device-height• orientation• aspect-ratio

• device-aspect-ratio• color• color-index• monochrome• resolution

Page 29: Responsive Web Design - Web & PHP Conference - 2013-09-18

Supported Media Properties• min/max-width• min/max-height• device-width• device-height• orientation• aspect-ratio

• device-aspect-ratio• color• color-index• monochrome• resolution

Page 30: Responsive Web Design - Web & PHP Conference - 2013-09-18

Little Pea Bakery

Page 31: Responsive Web Design - Web & PHP Conference - 2013-09-18

What about non-supportive browsers?css3-mediaqueries-js by Wouter van der

Graaf

Just include the script in your pages

Parses the CSS and applies style for

positive media tests

Page 32: Responsive Web Design - Web & PHP Conference - 2013-09-18

Patterns

Page 33: Responsive Web Design - Web & PHP Conference - 2013-09-18

Mostly Fluid

Page 34: Responsive Web Design - Web & PHP Conference - 2013-09-18

Column Drop

Page 35: Responsive Web Design - Web & PHP Conference - 2013-09-18

Layout Shifter

Page 36: Responsive Web Design - Web & PHP Conference - 2013-09-18

Tiny Tweaks

Page 37: Responsive Web Design - Web & PHP Conference - 2013-09-18

Off Canvas

Page 38: Responsive Web Design - Web & PHP Conference - 2013-09-18

Resources

Page 39: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 40: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 41: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 42: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 43: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 45: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 46: Responsive Web Design - Web & PHP Conference - 2013-09-18
Page 47: Responsive Web Design - Web & PHP Conference - 2013-09-18

Resources• http://www.alistapart.com/articles/responsive-web-design/• http://www.lukew.com/ff/entry.asp?1514• http://filamentgroup.com/examples/responsive-images/• http://code.google.com/p/css3-mediaqueries-js/• http://stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries• http://www.stunningcss3.com/index.php• http://www.abookapart.com/products/responsive-web-design• http://www.smashingmagazine.com/2011/07/22/responsive-web-design-techniques-tools-

and-design-strategies/• http://mediaqueri.es/• http://www.w3.org/TR/css3-mediaqueries/• http://dvcs.w3.org/hg/html-proposals/raw-file/tip/responsive-images/responsive-

images.html

Page 48: Responsive Web Design - Web & PHP Conference - 2013-09-18

Hey, what was that 4th thing?

Design

• Do we start with mobile-first?

• Is it best that all sites are responsive?

• Do we need or want to do visual comps for every device?

• Don’t dismiss mobile as walking and looking something up.

• We are at the beginning, that’s what makes this interesting!

Page 49: Responsive Web Design - Web & PHP Conference - 2013-09-18

Evaluation & Questions

http://wpc13.cnf.io/sessions/129

Page 50: Responsive Web Design - Web & PHP Conference - 2013-09-18

Frédéric Harper

[email protected]@fharper

http://hacks.mozilla.comhttp://outofcomfortzone.net


Top Related