Chris Mills will go beyond the obvious, looking at what we can do today to adapt our front-ends to different browsing environments, from mobiles and other alternative devices to older browsers we may be called upon to support. You’ll learn some advanced media query and viewport tricks, including a look at @viewport; insights into responsive images: problems, and current solutions; how to provide usable alternatives to older browsers with Modernizr; what other CSS3 modules provide responsive capabilities; and where media queries are going in the future, with CSS4 media queries.
2. Hi.I am chris mills.
‣ Open standards advocate and
Education agitator
‣ dev.opera.com editor
‣ W3C fellow, working
on webplatform.org
‣ Accessibility whiner
‣ HTML5/CSS3 wrangler
‣ Heavy metal drummer
and proud dad
Friday, 9 November 12
18. small tv rant
“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
Friday, 9 November 12
19. small tv rant
“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
Friday, 9 November 12
21. Back to the modern
world
Friday, 9 November 12
22. media="screen and (max-width: 481px)"
@media screen and (max-width: 481px) {
/* do amazing stuff for
narrow screens */
}
media queries
Friday, 9 November 12
28. Other
considerations
‣ Making replaced elements
responsive
‣ Bandwidth/loading of
resources
‣ Resolution
‣ Processing power
‣ Control mechanisms
Friday, 9 November 12
31. be warned
‣ Old IE versions don’t
support max-width, so you’ll
have to fallback to width:
100% instead.
Friday, 9 November 12
32. file size also
important
‣ Users on slow connections
won’t want to download huge
media files.
‣ We need to try to serve them
smaller files/alternatives.
‣ Assumptions: e.g. narrow
equals mobile equals slow
connection
Friday, 9 November 12
33. css resources easy
to deal with
‣ Use “mobile first”
‣ Load smaller resources by
default, and larger ones
inside MQs
‣ And in the future we’ve got
things like image-set coming
up (possibly...)
Friday, 9 November 12
34. Mobile first
example
header { background: url(small-
image.png); }
@media screen and (min-width: 480px) {
header { background: url(large-
image.png); }
}
Friday, 9 November 12
35. html5 video also
well served
<source src="crystal320.webm"
type="video/webm" media="all and (max-
width: 480px)">
<source src="crystal720.webm"
type="video/webm" media="all and (min-
width: 481px)">
Friday, 9 November 12
36. But html images are
not so lucky
<img src="thats-all-folks.png"> ?
Friday, 9 November 12
38. adaptive-images
‣ 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.
Friday, 9 November 12
39. the picture element
<picture alt="a picture of something">
<source src="mobile.jpg">
<source src="medium.jpg" media="min
width: 600px">
<source src="fullsize.jpg" media="min
width: 900px">
<img src="mobile.jpg">
<!-- fallback for
non-supporting browsers -->
</picture>
Friday, 9 November 12
40. suggested solutions
‣ Srcset
‣ New image formats?
‣ Defined the media tests in
meta tags?
‣ New headers and protocols?
Friday, 9 November 12
41. processing power
‣ You might want to turn off
effects like shadows,
gradients and animations for
small screen devices.
‣ CSS effects are arguably
less power draining than JS
or Flash, but even so.
‣ They can cause the display
to look cluttered too.
Friday, 9 November 12
47. now we have hi
fidelity devices
‣ e.g. iPhone 4s is 960 x 640
pixels at 326ppi
‣ These devices lie twice
‣ One CSS pixel = multiple
device pixels
‣ Images can start to look
pixellated
Friday, 9 November 12
51. soon to be
replaced by
@media screen and (resolution: 1.5dppx)
{
body { background-size: 250px; }
}
Friday, 9 November 12
52. tell the truth with
viewport
<meta name="viewport"
content="width=device-width,
target-densitydpi=device-dpi">
Friday, 9 November 12
53. All good but...
‣ Images may now start to look
a little small
‣ You could serve larger
images for devices with
higher resolutions
Friday, 9 November 12
54. control mechanisms
‣ Currently tricky
‣ Usual wisdom about web sites
applies — make pages
keyboard accessible, etc.
‣ Can’t be detected in
CSS(yet)
‣ JavaScript touch detection
is an option — Modernizr,
jQuery
Friday, 9 November 12
56. old ie versions
‣ Lack support for media
queries
‣ Although we don’t get old IE
on small screen devices
‣ But mobile first is a
problem
Friday, 9 November 12
57. solutions
‣ Provide fallbacks such as
simpler layouts or pixels
instead of % or rems
‣ Use a media query polyfill
such as respond.js
Friday, 9 November 12
66. worthy of note
‣ CSS device adaptation
‣ Flexbox
‣ Multi-col
‣ (Regions, Grids, etc.)
Friday, 9 November 12
67. CSS device
adaptation
‣ Because viewport is really
more of a CSS type thing
than an HTML type thing
‣ This spec provides a
@viewport at-rule to contain
viewport equivalents
‣ Currently supported in Opera
and IE10, with prefixes
‣ dev.opera.com/articles/view/
an-introduction-to-meta-
viewport-and-viewport
Friday, 9 November 12
69. Flex box
‣ A spec for easier UI
layout
‣ Makes certain layout tasks
much easier
‣ New syntax support
currently very limited
‣ Old syntax supported
in most modern
browsers
Friday, 9 November 12
82. multi col
‣ A spec for breaking content
into multiple columns.
‣ Column widths/numbers,
column rules, column
spacing, column gaps, column
breaks.
‣ Supported across all major
browsers, mostly.
Friday, 9 November 12
87. script MQ
@media screen and (script) {...}
@media screen and not (script) {...}
Friday, 9 November 12
88. hover MQ
The ‘hover’ media feature is
used to query whether the
primary pointing system used
on the output device can
hover or not.
@media screen and (hover) {...}
Friday, 9 November 12
89. pointer MQ
@media screen and (pointer: coarse) {...}
‣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.
Friday, 9 November 12
90. luminosity MQ
@media screen and (luminosity: dim) {...}
‣dim: The device is being used
in a dim environment, such as
nighttime.
‣normal: The device is being
used in average lighting
conditions, which don’t
require significant
adjustment.
‣washed: The device is being
used in washed out
conditions, e.g. in bright
sunlight.
Friday, 9 November 12
91. other future MQs
@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
}
Friday, 9 November 12
92. other future MQs
@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
}
Friday, 9 November 12
93. other future MQs
@media (remote) {
// TV or set-top box?
}
@media (remote) and (hover) {
// Wii?
}
Friday, 9 November 12
94. other future MQs
@media (network: v-slow) {...}
“It has been proposed. Most
people agree that it would be
cool, nobody has a clue about
how to spec it ... submit
proposals to me or to www-
style@w3.org. Use [css4-
mediaqueries] in the subject
line, and read lists.w3.org/
Archives/Public/wwwstyle/
2012Mar/0691.html first.”
-- Florian Rivoal
Friday, 9 November 12