From meta viewport to @viewport and from device-pixel-ratio to the resolution media query: various responsive design hooks are undergoing standardization, allowing for future-proof sites that work well in different contexts. In addition, new CSS features like object-fit, relative length units and so on are increasingly supported by browsers as well, and allow for more versatile responsive design solutions. In my talk, I will look at these features and explain how they can be used in websites today.
10. Four new CSS features to optimize
websites for different devices.
11. Four new CSS features to optimize
websites for different devices.
@viewport
viewport-percentage lengths
resolution media queries
object-fit & object-position
CSS image values
22. “Gerstner defined a design “programme” as a set of rules for constructing a
range of visual solutions. Connecting his methodology with the new field of
computer programming, Gerstner presented examples of computer-
generated patterns that were made by mathematically describing visual
elements and combining them according to simple rules.”
!
— Ellen Lupton, Thinking with Type (2nd edition), 2010, Princeton Architectural Press, p165
23. Karl Gerstner, Programme entwerfen, 2007. Copyright 2007 Lars Müller Publishers — used with kind permission.
24. FFWD to today
Image from http://www.html5rocks.com/en/tutorials/tooling/synchronized-cross-device-testing/ by Addy Osmani for HTML5 Rocks. CC-BY 3.0.
46. Safari on iPad applies a 1.333× zoom in
landscape mode even although
width=device-width is set.
it’snota
realstandard…
47. width=device-width, initial-scale=1
forces a 1× zoom. Say what?
it’snota
realstandard…Safari on iPad applies a 1.333× zoom in
landscape mode even although
width=device-width is set.
48. And when we thought things were
stable, Safari introduced a new,
minimal-ui property.
it’snota
realstandard…
65. for widths up to 400px:
meta name=viewport content=width=400
for widths larger than 400px:
meta name=viewport content=width=device-width
Corresponds to
@viewport {
width: 400px auto;
}
74. 1 device px 2,25 device px 4 device px 9 device px
What’s in a (CSS) pixel?
Macbook Aire.g. HTC Desire iPhone 4 HTC One
75. 1 device px 2,25 device px 4 device px 9 device px
What’s in a (CSS) pixel?
this makes graphics look blurry…
(unless you serve oversized ones that are scaled down)
77. 1 device px 2,25 device px 4 device px 9 device px
this makes graphics look blurry…
resolution media queries
hence:
(responsive image spec)
78. 1 device px 2,25 device px 4 device px 9 device px
1 dppx 1,5 dppx 2 dppx 3 dppx
What’s in a (CSS) pixel?
(can) use dots per ‘px’ unitsresolution media queries
79. body {background: url(bg.png) 0 0 repeat;}
@media (screen and min-resolution: 2dppx) {
body {background-size: 50% !important;}
}
@media (screen and min-resolution: 3dppx) {
body {background-size: 33.3% !important;}
}
resolution media queries
80. body {background: url(bg.png) 0 0 repeat;}
@media (screen and min-resolution: 2dppx) {
body {background-size: 50% !important;}
}
@media (screen and min-resolution: 3dppx) {
body {background-size: 33.3% !important;}
}
resolution media queries
Pattern from http://subtlepatterns.com/tree-bark/ by Getdiscount. CC-BY-SA 2.0.
81. body {background: url(bg.png) 0 0 repeat;}
@media (screen and min-resolution: 2dppx) {
body {background-size: 50% !important;}
}
@media (screen and min-resolution: 3dppx) {
body {background-size: 33.3% !important;}
}
resolution media queries
82. body {background: url(bg.png) 0 0 repeat;}
@media (screen and min-resolution: 2dppx) {
body {background-size: 50% !important;}
}
@media (screen and min-resolution: 3dppx) {
body {background-size: 33.3% !important;}
}
resolution media queries
84. If this looks familiar…
It’s very similar to device-pixel-ratio,
but resolution is standardized, and
comes without quirky vendor prefixes.
!
However, for now, use both…
100. 100 × 100
1vw = 1/100 of viewport width
1vh = 1/100 of viewport height
101. 100 × 100
1vw = 1/100 of viewport width
1vh = 1/100 of viewport height
1vmax = 1/100 of whichever is bigger
1vmin = 1/100 of whichever is smaller
102. 100 × 100
vw, vh, vmax, vmin
can be used with font-size, width,
height, etc. to create designs that
work with small viewports, not
fight against them.
105. Four new CSS features to optimize
websites for different devices.
@viewport
viewport-percentage lengths
resolution media queries
object-fit object-position
CSS image values