Responsive Web design challenges Web designers to adapt a new mindset to their design and coding processes. This talk provides an overview of various practical techniques, tips and tricks that you might want to be aware of when working on a new responsive design project.
8. When Sydney J. Harris said that, he meant
human society and our understanding of
computers. But it can relate to what we do as
we'll. When we think about the Web, what do
ā
The dangerous thing is not that
machines might start thinking like
humans, but that humans might start
thinking like machines.
ā Sydney J. Harris
9. We are blinded by chrome. When it
comes to RWD, we think about layouts,
and often we should, but we have to
keep in mind that we are not rectangle
artists. we explore solutions to
problems. Browsers think in boxes, but
humans shouldn't.
10. Wir denken dass das Web so aussieht.
Als Designer sehen wir uns oft als Pixel-Pusher
oder Rectangle Zeichner. So sieht das Web aber
nicht aus
When it comes to responsive design, we think
about layouts, and sometimes we should, but we
have to keep in mind that we arenāt rectangle
artists. We explore solutions to problems.
11. A ļ¬uid, unpredictable, chaotic,
interconnected environment
with plenty of right and wrong
solutions. I always feel weird
about blog posts on why RWD is
a wrong technique, or HTML5/
native is a wrong solution. The
Web isnāt black and white, itās
rich, extremely diverse and it
requires pragmatic thinking.
15. ā
Media queries can be used to do
more than patch broken layouts:
with proper planning, we can
begin to choreograph content
proportional to screen size,
serving the best possible
experience at any width.
ā Trent Walton
16.
17.
18. Content Choreography
ā¢ From the technical standpoint, arrangement
of boxes is often implemented using Flexbox.
@media screen and
(max-width: 33.236em) {
#main { display: flex; }
#main > nav,
#main > aside { flex: 1; }
#main > article { flex: 2; }
#main > nav { order: 0; }
#main > article { order: 1; }
#main > aside { order: 2; }
19.
20. We can manipulate
experiences to make
them genuine across
different viewports ā
be it desktop, mobile or
anything else.
29. Resolution Independence
ā¢ High pixel density displays prompt us to
create future-proof solutions for graphics.
ā¢ Creating multiple assets for the same
graphics (not photos) isnāt future-proof.
ā¢ Two options: SVG and Icon Fonts.
32. Resolution Independence (SVG)
ā¢ SVG ļ¬les are usually larger and browsers
need more time to rasterize and display them.
ā¢ Good SVG support: Chrome 4+, Safari 4+,
FF4+, Opera 9.5+, IE9+, mobile browsers.
ā¢ For legacy browsers (and Android 2.3)
we need PNG-fallback with Conditional
Comments (IE<9) or Modernizr.
35. Resolution Independence
(Web Fonts)
ā¢ There are many comprehensive Web fonts:
Entypo and FontAwesome are free.
ā¢ Excellent support: everywhere but Opera
Mini and Android 2.1.
ā¢ Build custom, small ābundlesā with Fontello
(combines popular open-source fonts).
38. Compressive Images
ā¢ To display photos properly on high pixel
density displays, we donāt need hi-res images.
ā¢ If a JPG image has relatively small dimensions,
we can use a workaround to keep its size small.
ā¢ Solution: given a ānormalā image resolution,
double it and use minimal JPEG compression.
39. ā
...Given two identical images that
are displayed at the same size on a
website, one can be dramatically
smaller than the other in ļ¬le size
if itās highly compressed and
dramatically larger in dimensions
than it is displayed.
ā Daan Jobsis
46. ā
If you [...] had to choose between
employing media queries to make
the design look good on a mobile
device or optimizing the site for
performance, you would be better
served by making the desktop site
blazingly fast.
ā Jason Grigsby
47. Conditional CSS
ā¢ We ask browsers to load assets progressively ā
and only when they can be displayed.
ā¢ Idea: if a CSS media query was ļ¬red, catch it
with JavaScript and load additional assets.
ā¢ CSS:
@media all and (min-width: 45em) {
body:after {
content: 'desktop';
display: none;
}
}
48. Conditional CSS
ā¢ CSS:
@media all and (min-width: 45em) {
body:after {
content: 'desktop';
display: none;
}
}
ā¢ JS:
var size =
window.getComputedStyle(document.body,':after').get
PropertyValue('content');
if (size == 'desktop') {
// Load some more content.
}
55. Gmailās Lazy Loading
ā¢ Latency is the time between when a browser
requests a resource from a server and when it
starts to receive the serverās response.
ā¢ On mobile, latency is a major UX killer. For a
1Mb page with 85 requests per page, it is 4.5s!
ā¢ JavaScript is expensive; parsing takes time and
blocks the rendering of the page. Usually you
donāt need all JavaScript right away.
56. Gmailās Lazy Loading
ā¢ Idea: let browsers download all of the JS right
away, but evaluate it āon demandā, i.e. when
users need a particular feature.
ā¢ Much of the downloaded JS is commented out,
and when needed uncommented and eval-ed.
ā¢ Gmailās case:
200 Kb of JS -> 2600 ms page load
200 Kb of JS (lazy loaded) -> 240 ms page load
57. Gmailās Lazy Loading
ā¢ <script id="lazy">
// Make sure you strip out (or replace) comment
blocks in your JavaScript first.
/* JavaScript of lazy module */
</script>
<script>
function lazyLoad() {
var lazyElement = document.getElementById('lazy');
var lazyElementBody = lazyElement.innerHTML;
var jsCode = stripOutCommentBlock(lazyElementBody);
eval(jsCode); }
</script>
<div onclick=lazyLoad()>Lazy Load</div>
58.
59. The Two-Click Social Widget
ā¢ Load social widgets only when user explicitly
chooses to take that action to share content.
ā¢ Idea: load small social icons by default, and
load the FB, Twitter and G+ widgets on click.
ā¢ Cuts down on bandwidth and on latency.
(FB button alone weighs 120 Kb + 4 requests).
63. Protecting Image Aspect Ratios
ā¢ When max-width: 100%; is applied to an
image with width and height attributes
deļ¬ned in HTML, image rescales incorrectly.
ā¢ Solution: add height: auto; for images to
which max-width: 100% is applied.
ā¢ CSS:
img, video { max-width: 100%; height: auto; }
64. Intrinsic Ratio For Videos
ā¢ To ensure the intrinsic 4:3 or 16:9 ratios for
videos, we create a box with the proper ratio,
then stretch the video inside to ļ¬t the
dimensions of the box.
ā¢ HTML:
<div class="wrapper-with-intrinsic-ratio">
<div class="element-to-stretch"></div>
</div>
69. Responsive Videos
ā¢ We can serve diļ¬erent video ļ¬les to diļ¬erent
devices by using media attribute on the
video <source> attribute.
ā¢ Supported in the latest versions of Chrome,
Opera, Safari, FF 15+, IE9+, mobile browsers.
70. Responsive Videos
ā¢ HTML:
<video controls preload="none">
<source type="video/mp4" src="video_small.mp4"
media="all and (max-width: 480px),
all and (max-device-width: 480px)">
<source type="video/webm" src="video_small.webm"
media="all and (max-width: 480px),
all and (max-device-width: 480px)">
<source type="video/mp4" src="video.mp4">
<source type="video/webm" src="video.webm">
<!-- proper fallback content goes here -->
</video>
72. Vertical Media Queries
ā¢ min-height and max-height are useful for
adjusting the font-size, padding, margin and
cropping images.
ā¢ Beware of h/v-media queries collisions when
resizing the browser. Things might easily
get out of control.
73.
74.
75. Media Queries Splitting
ā¢ In development, we can use a breakpoint-
based organization for CSS (āmin-widthā):
0-up.css, 450-up.css, 720-up.css etc.
ā¢ We can also set breakpoints 1px apart and
split styles instead of overriding from one
media query to the next (āmin/max-widthā):
base.css, 0-449.css, 450-719.css etc.
76. Media Queries Splitting
ā¢ In practice, itās often a good starting point to
work with em media queries right away.
0-up.css, 25em-up.css, 35em-up.css etc.
ā¢ If itās not an option, itās a good idea to convert
px to em for production code to improve
maintenance and avoid zooming issues.
80. ā
Designing for the Web is like
visualizing a tesseract. We build
experiences by manipulating their
shadows.
ā Tim Brown
81. Debugging Media Queries
ā¢ Due to lack of convenient tools, debugging
RWD often feels like groping in the dark.
There are some popular techniques though.
ā¢ Setting the body bg color to diļ¬erent colors for
each breakpoint. Also box-sizing: border-box.
ā¢ The * technique for testing for optimal
measure in the browser.
82.
83.
84.
85. People like to test a number
of metrics to see why people
are not * staying on a site. I
think sometimes we spend
so much time focusin* g on
*
analytics that we have no...
86. People like to test a number
of metrics to see why people
are not * staying on a site. I
think sometimes we spend
so much time focusin* g on
*
analytics that we have no...
99. Our design process was deļ¬ned by one
major constraint: perfect measure.
100. ā
If we could adequately typeset an article and
thus establish the general context of the
design, everything else would follow. [...]
The key attribute for achieving perfect
typesetting was perfect measure: a good
average between 45 and 90 characters per
lineāon all screen resolutions.
ā Elliot Jay Stocks, āSmashing Book 3ā
101. So we started looking for typefaces that would best express our
new vision, values and our deisgn persona...and oh boy were we
excited. We felt like a kid in a candy store... until we had to be
thrown into cold shower.
With the abundance of rich typefaces on the Web, we excitedly
jumped into the myriad of possibilities. We experimented with
literally dozens of typefaces from several type foundries in various
pairings: we considered Centro Sans and Centro Serif, Meta and
Meta Serif, Adelle, Ronnia, LFT Etica, FF Tisa, just to name a few.
We observed how they looked at diļ¬erent font sizes and how well
they worked together. We examined how well they appeared in bold
and italic and in headings and body copy, as well as how they worked
in less obvious contexts such as image captions.
102.
103. Typefaces should be optimized for
long reading on (many) screens and
ļ¬t various contexts.
104.
105.
106.
107. We started out with setting up a couple of demo pages for
typography, including links, italics, bold.
With all design distractions removed, we could pay a great
deal of technical attention to the type once we set up our
basic styles. How legible is this typeface at a particular size?
How well does it perform on Windows? Is there a superior
version from an alternative font delivery network that
perhaps uses PostScript outlines for display sizes?
Focusing on these ļ¬ne details is much easier when youāre
looking purely at the type and nothing else.
Because thereās a lot going on visually on Smashing
Magazineāscreenshots, buttons and noisy adsāa sans-serif
felt like a more sensible, uncluttered route for body copy. In
fact, it was diļ¬cult to imagine a serif typeface being used for
code-heavy articles in the coding section.
108. Sorry, Proxima Nova rendering is
incorrect on this screenshot, but we
lost the original ļ¬les. :-)
109.
110.
111.
112.
113.
114.
115.
116.
117. We started from mobile, and worked
our way upwards to desktop views.
118.
119.
120. The keywords were carefully
chosen and tested.
Navigation changes: we We kned that it would take too
used t wo markups: one much space, but we decided to test
with select, another it and it performed fairly well.
with a nested unordered
list. and switches them Weāve developed a toggle menu here
on and off with CSS. as well, it is currently in the queue
for testing. We had drop-down...
initially here...
121.
122.
123.
124.
125. We never targeted speciļ¬c devicesā
and introduced media queries
whenever it felt natural to do so.
131. Responsive Design Patterns
ā¢ Responsive design aļ¬ects all design assets:
layout, images, type, navigation, tables,
calendars, galleries, forms, maps, ads...
ā¢ Oļ¬ine access and mobile UX enhancements
complement RWD very well (e.g. HTML5
localStorage, GeoLocation, Telephone links).
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143. Responsive Design Patterns
ā¢ Media queries arenāt supported in Android
2.1 native client, Gmail app on all platforms,
Win Mobile 6.1 & Phone 7, BlackBerry OS 5.
ā¢ Also, Webmail services tend to ignore media
queries and overwrite them with their custom
CSS code.
157. Image credits
ā¢ Front cover: Geometric Wallpapers
by Simon C Page (http://simoncpage.co.uk/
blog/2012/03/ipad-hd-retina-wallpaper/)
ā¢ Homer Simpsons: http://smashed.by/homer,
http://smashed.by/crazy-homer