Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bruce Lawson Over The Air 2012

Bruce Lawson Over The Air 2012

Responsive Web Design: the sex behind the specs

(moving so fast these days, I had to re-write the "future" section since I wrote it 3 weeks ago!)

bruce lawson

June 03, 2012

More Decks by bruce lawson

Other Decks in Technology


  1. Rule of thumbs Like accessibility, retrofitting for RWD on a

    non-trivial site (eg, different templates, data tables etc) is an order of magnitude more expensive than building it RWD from scratch.
  2. CSS 3 Media Queries • builds on CSS 2.1 Media

    Types concept • more granular control (not just screen, print...) http://www.w3.org/TR/css3-mediaqueries/
  3. CSS 3 Media Queries <link rel="stylesheet" ... media="screen and (max-width:480px)"

    href="..."> @import url("...") screen and (max-width:480px); @media screen and (max-width:480px) { // insert CSS rules here }
  4. Multiple expressions – and keyword @media screen and (min-width:180px) and

    (max- width:480px) { // screen device and width > 180px // and width < 480px }
  5. Multiple expressions – comma separated @media screen and (min-width:800px), print

    and (min-width:20em) { // screen device with width > 800px // or print device with width > 20em }
  6. Negative expressions – not keyword @media not screen and (min-width:800px)

    { // not applied to screen device // with width > 800px }
  7. Exclusive expressions – only keyword @media only screen and (min-width:800px)

    { // only applied to screen device // with width > 800px }
  8. Multiple media queries /* “The absence of a media query

    is the first media query” Bryan Rieger */ @media screen and (max-width:480px) { // screen device and width < 480px } @media screen and (max-width:980px) { // screen device and width < 980px } @media screen and (min-width:980px) { // screen device and width > 980px }
  9. no viewport defined in <head>, so fallback to default of

    980px, which is squeezed inside 320px.
  10. viewport meta <meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=320, initial- scale=2.3,user-scalable=no">

  11. If you're using Media Queries: <meta name="viewport" content="width=device-width"> If you

    have an explicit width: <meta name="viewport" content="width=550">
  12. CSS Device Adaptation @viewport { width: 320px; zoom: 2.3; user-zoom:

    fixed; } Opera Mobile, Opera Mini, Internet Explorer 10 with prefixes www.w3.org/TR/css-device-adapt dev.opera.com/articles/view/an-introduction-to-meta-viewport-and-viewport
  13. Viewport properties width / min-width / max-width user-zoom height /

    min-height / max-height orientation zoom / min-zoom / max-zoom resolution
  14. <meta name="viewport" content="width=550,maximum- scale=1.0,target-densitydpi=device-dpi"> @media screen { @-o-viewport { /*

    undo meta viewport settings */ width: auto; max-zoom: auto; } } @media screen and (max-device-width: 550px) { @-o-viewport { /* 550px viewport on small screen devices */ width: 550px; } }
  15. <meta name="viewport" content="width=550,maximum- scale=1.0,target-densitydpi=device-dpi"> @media screen { @-o-viewport { /*

    undo meta viewport settings */ width: auto; max-zoom: auto; } } @media screen and (max-device-width: 550px) { @-o-viewport { /* 550px viewport on small screen devices */ width: 550px; } }
  16. matchMedia if (window.matchMedia("(min-width: 400px)").matches) { /* the view port is

    at least 400 pixels wide */ } else { /* the view port is less than 400 pixels wide */ } For IE9+ and Opera, polyfill github.com/paulirish/matchMedia.js/
  17. fixmystreet.com @media screen and (max-width: 480px) { body {display: table;

    caption-side: bottom;} Nav { float: none; display: table-caption; width:100%; } }
  18. adaptive-images.com Add .htaccess and adaptive-images.php to your document- root folder.

    Add one line of JavaScript into the <head> of your site. Add your CSS Media Query values into $resolutions in the PHP file.
  19. Super WebKit-tastic CSS selector {background: image-set (url(foo-lowres.png) 1x, url(foo-highres.png) 2x)

    center;} selector {background: image-set (url(foo-lowres.png) 1x low-bandwidth, url(foo-highres.png) 2x high-bandwidth);} http://lists.w3.org/Archives/Public/www-style/2012Feb/1103.html
  20. .. extrapolate to HTML? <img src="face-600-200-at-1.jpeg" alt="" srcset="face-600-200-at-1.jpeg 600w 200h

    1x, face-600-200-at-2.jpeg 600w 200h 2x, face-icon.png 200w 200h"> A comma-separated list of URLs each with one or more descriptors giving the maximum viewport dimensions and pixel density allowed to use the image.
  21. Media Query "hints" From the available options, the user agent

    then picks the most appropriate image. If the viewport dimensions or pixel density changes, the user agent can replace the image data with a new image on the fly.
  22. Script media query @media screen and (script) {...} @media screen

    and not (script) {…} http://lists.w3.org/Archives/Public/www-style/2012Jan/0034.html
  23. hover media query The ‘hover’ media feature is used to

    query whether primary pointing system used on the output device can hover or not.
  24. pointer media query none The input mechanism of the device

    does not include a pointing device. coarse The input mechanism of the device includes a pointing device of limited accuracy. fine The input mechanism of the device includes an accurate pointing device.
  25. @media (paged) and (interactive:0) { // I am like a

    printer } @media (paged) and (interactive) { // I'm a projector, or like a Kindle } @media (paged) and (interactive) and (touch) { // I'm like a touch-screen Kindle }
  26. @media (touch) and (max-width: 480) { // looks like an

    smart phone } @media (touch) and (keyboard) and (min-width:600) { // looks like a touch-screen laptop }
  27. @media (remote) { // TV or set-top box? } @media

    (remote) and (hover) { // Wii? }
  28. Tangent about web on TV "Searching, browsing, updating and buffering

    are not TV- like. In fact an enormous number of people found that the technology they had purchased wasn't what they expected at all, that they were bringing the worst parts of using a computer into the television environment." www.insideci.co.uk/news/rovi-research-reveals-changing-consumer-habits.aspx
  29. OMG watchin TV LOL #justsayin Most consumers have up to

    five devices that do social media better than a TV. Consumer engagement with social media is inversely proportional to the size of the screen used for it.
  30. No shit, sherlock! Teenagers were "horrified at the prospect of

    displaying their social activities on the family TV." Image from www.buzzfeed.com/scott/holy-shit-halloween-costume
  31. @media (network: v-slow) {..} Florian: "It has been proposed. Most

    people agree that it would be cool, nobody has a clue about how to spec it in a way that is useful and implementable. If you find people with a clue, encourage them to submit proposals to me or to [email protected]. Use [css4-mediaqueries] in the subject line, and read lists.w3.org/Archives/Public/www- style/2012Mar/0691.html first."