Would you like to make your website work on a variety of screens, from tiny mobile devices to enormous desktops? In this session, we'll demonstrate how to retrofit a fixed-width site with basic responsive design features. You'll learn about tools and techniques for previewing your responsive site, find out how to create scalable images, discover ways to plan flexible and consistent web typography, and see the latest design approaches for responsive menu systems. Some experience with HTML and CSS will help you get the most out of this session.
12. REACHYOUR AUDIENCE
American Adults (Jan 2014)
² 90% have a cell phone
² 58% have a smartphone
² 42% own a tablet computer
34% OF cell internet users go online
mostly using their phones
Source: pewinternet.org/fact-sheets/mobile-technology-fact-sheet/
(updated regularly)
A
41. ADD A VIEWPORTMETATAG
<meta name="viewport"
content="width=device-width, initial-scale=1">
² sizes content to the device’s viewport width
² ensures layout is not zoomed out on load
² Use both rules to ensure maximum compatibility
43. SAVE US FROM compatibilityMODE
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
² Ensures content is displayed with the most recent
IE rendering engine
² Unless it’s an “intranet”
² Google “Compatibility view and
‘Smart Defaults’” for more info
p
45. Uh oh, browser support
² No media query support in <IE 8, Safari 2,
Firefox 1,2
² Include css3-mediaqueries.js
by Wouter van der Graff
² code.google.com/p/css3-mediaqueries-js/
46. SMALLESTOR LARGESTsizes FIRST?
² Putting smallest sizes first utilizes the cascade,
gets around IE8 issues
² I write largest to smallest, then re-arrange
before launch
47. MULTIPLE CSS FILES?
Your choice. I separate them for side-by-side viewing.
<link rel="stylesheet" type="text/css" href=“/style.css">
<link rel="stylesheet" type="text/css" href=“/responsive.css">
48. BASIC MEDIA QUERYFoRMAT
#container { width: 960px; }
@media only screen and (max-width: 960px ) {
#container { width: 100%; }
}
style.css
responsive.css
49. STARTWITH large containers
² Change px or em widths to percentages
² Remove floats
² Check padding – may not need as much
58. Examine padding
² Use less vertical padding to save mobile
users from scrolling
² Don’t remove too much space
² Keep targets big
59. Responsivetypography
• More than just resizing the container and
letting text reflow
• Use resizable units: em or rem, not px
• Keep line height flexible too – and specify it
60. TRYusing REM UNITS
• REM = Relative EM
• Sizes text from the context of the root
element (html), not the container
• Avoids extra math
• Not supported by <IE8, so use px as backup
61. Sizing in PX and rem
@media only screen and ( max-width: 500px ) {
body { font-size: 62.5%; }
#site-name h1 {
font-size: 24px; font-size: 2.4rem;
line-height: 24px; line-height: 2.4rem;
}
}
responsive.css
73. PICTUREFILL
² Serves up images based on screen size
² A little extra markup and a tiny JavaScript
² Includes support for IE8 and <noscript>
² Can be called programmatically
² github.com/scottjehl/picturefill
N
74. PICTUREFILL EXAMPLE
<span
data-‐picture
data-‐alt="Jell-‐O">
<span
data-‐src="images/retrofood-‐feature-‐500.jpg"></span>
<span
data-‐src="images/retrofood-‐feature-‐790.jpg"
data-‐media="(min-‐width:
500px)"></span>
<span
data-‐src="images/retrofood-‐feature.jpg"
data-‐media="(min-‐width:
790px)"></span>
<!-‐-‐
Fallback
content
for
non-‐JS
browsers.
Same
img
src
as
the
iniMal
img.
-‐-‐>
<noscript><img
src="images/retrofood-‐feature-‐500.jpg"
alt="Jell-‐O"></noscript>
</span>
N<script>
//
Picture
element
HTML
shim|v
it
for
old
IE
(pairs
with
Picturefill.js)
document.createElement(
"picture"
);
</script>
<script
async="true"
src="scripts/picturefill.js"></script>
83. Basic usertesting
² Ask someone else to use it
² Load it over a slow connection
² Try lots of devices
² Utilize testing software (BrowserStack.com)
² Cheap and worth it!