SlideShare a Scribd company logo
1 of 124
Download to read offline
Optimizing your layout
for phones and tablets
using viewport and
media queries
Andreas Bovens - Opera Software
about me




           http://www.ļ¬‚ickr.com/pho
                                   tos/thomaaas/4783952591
                                                          /
about me




           http://www.ļ¬‚ickr.com/pho
                                   tos/thomaaas/4783952591
                                                          /
about me




                                                             http://www.ļ¬‚ickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.ļ¬‚ickr.c
about me




                                                             http://www.ļ¬‚ickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.ļ¬‚ickr.c
about me




                                                             http://www.ļ¬‚ickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.ļ¬‚ickr.c




                                                                                                               http://www.ļ¬‚ickr.com/photos/forcery/
                                                                                                                                                   3511170176/
Bruce Lawson                       Daniel Davis




                                      Divya Manian
                Chris Mills
                                                                            Karl Dubost




                     Shwetank Dixit                    Tiffany Brown
                                                                        Andreas Bovens

                                      Luz Caballero


Patrick Lauke
                     Zi Bin Cheah                     Vadim Makeev           Mike Taylor
ā€œPatterns for
Multiscreen
Strategiesā€
                                                 Coherence                      Syncronization                   Screen sharing



By Precious   http://slidesha.re/kiip5y



                                               Device shifting                 Complementarity                     Simultaneity

                                          These patterns should help understand and define strategies for the multiscreen world.
Coherence                      Syncronization                   Screen sharing




     Device shifting                 Complementarity                     Simultaneity

These patterns should help understand and define strategies for the multiscreen world.

                                                                                  http://slidesha.re/kiip5y
ā€œA digital product or
service looks and
works coherently
across devices.
Features are optimized
for speciļ¬c device
characteristics and
usage scenarios.ā€        Coherence
                                     http://slidesha.re/kiip5y
Coherence
        http://slidesha.re/kiip5y
?
show top-left and pan
small screen rendering
         aka single column view
zoom and pan
Thatā€™s all nice,
but what if I want to control
  this zooming behavior?
Answer:
viewport meta
This is the viewport
(not just this)
Most commonly
though, youā€™ll want to
focus on controlling
page width...
<meta ...>
             ... using a "viewport"
             meta tag in the
             <head> of the page.
works in:




with some exceptions ;-)
http://www.opera.com/developer/tools/mobile/
HVGA portrait
HVGA portrait
HVGA portrait




                no viewport deļ¬ned in <head>,
                so fallback to default of 850px,
                which is squeezed inside 320px.
HVGA portrait




                <meta name="viewport"
                content="width=320">
HVGA portrait




                <meta name="viewport"
                content="width=320">
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="width=320">
HVGA portrait




                <meta name="viewport"
                content="width=device-width">
HVGA portrait




                <meta name="viewport"
                content="width=device-width">
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="width=device-width">
HVGA landscape   HVGA landscape




      480px
                       320px Ɨ 1.5 zoom
HVGA landscape   HVGA landscape




      480px
                       320px Ɨ 1.5 zoom
HVGA portrait




                <meta name="viewport"
                content="initial-scale=1">
HVGA portrait




                <meta name="viewport"
                content="initial-scale=1">
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="initial-scale=1">
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="initial-scale=1">
                     (same result as width=device-width)
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="initial-scale=0.5">
HVGA portrait   HVGA landscape




                <meta name="viewport"
                content="initial-scale=2">
<meta name="viewport"
content="width=device-width">

+
<div style="width: 600px">
HVGA portrait




                <meta name="viewport"
                content="width=device-width">

                +
                <div style="width: 600px">
HVGA portrait




                <meta name="viewport"
                content="width=device-width,
                initial-scale=1">
                +
                <div style="width: 600px">
other stuff
maximum-scale=... , minimum-scale=...
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
user-scalable=yes|no
<meta name="viewport" content="width=320, user-scalable=no">
height=...
<meta name="viewport" content="height=device-height">
other stuff
maximum-scale=... , minimum-scale=...
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
user-scalable=yes|no
<meta name="viewport" content="width=320, user-scalable=no">
height=...
<meta name="viewport" content="height=device-height">
other stuff
maximum-scale=... , minimum-scale=...
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
user-scalable=yes|no
<meta name="viewport" content="width=320, user-scalable=no">
height=...
<meta name="viewport" content="height=device-height">
other stuff
maximum-scale=... , minimum-scale=...
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
user-scalable=yes|no
<meta name="viewport" content="width=320, user-scalable=no">
height=...
<meta name="viewport" content="height=device-height">
NB:
Make sure to use commas, not semi-colons as
delimiters between viewport values!
Remember this, especially when syntax-googling ;-)
http://www.ļ¬‚ickr.com/photos/33284937@N04/4771132618/
So, how to use this?
Snifļ¬ng for mobile
browsers maybe?
So, how to use this?
Snifļ¬ng for mobile
browsers maybe?
Better donā€™t sniff.
Opera/9.80 (Macintosh; Intel Mac OS X 10.5.8; U; en) Presto/2.9.220 Version/12.00
Opera/9.80 (Macintosh; Intel Mac OS X 10.5.8; U; en) Presto/2.9.220 Version/12.00
So, avoid snifļ¬ng,
but if you really have to,
provide a way for users
to make corrections.
So, avoid snifļ¬ng,
but if you really have to*,
provide a way for users
to make corrections.

* always ask yourself why the mobile site should be
different from the desktop site
* always ask yourself why the mobile site should be
     different from the desktop site


customer requir
                   ements
                                          tim e restrictions

                  budget limitations

capabilities are different
                                  different layout needed
* always ask yourself why the mobile site should be
     different from the desktop site


customer requir
                   ements
                                          tim e restrictions

                   budget limitations

capabilities are different
                                  different layout needed
     capability detection
* always ask yourself why the mobile site should be
     different from the desktop site


customer requir
                   ements
                                          tim e restrictions

                   budget limitations

capabilities are different
                                  different layout needed
     capability detection
                                     viewport + media queries
Letā€™s talk about
viewport + media queries
media queries
Media queries are conditional hooks
for applying different CSS rules,
depending on e.g. browser width,
screen height, aspect ratio, etc.
Differently said, media queries
allow you to optimize your site
layout for all kinds of form factors.




                              Via http://mediaqueri.es/
@media screen and (min-width: 400px) {
   article {
      border: 5px solid hsla(32, 98%, 51%, 1);
      box-shadow: hsla(0, 100%, 0%, 0.5) 0 0 10px;
      max-width: 800px;
      margin: 0 auto 0 auto;
      }
 }
@media screen and (min-width: 400px)
and (max-width: 800px) {
   article {
      /* css for browsers with width ā‰„ 400px and
         ā‰¤ 800px */
      }
 }
@media screen and (min-width: 400px),
not projection and (aspect-ratio: 16/9) {
   article {
      /* css for browsers with width ā‰„ 400px,
          except projectors with 16/9 aspect ratio */
      }
 }
@media screen and (max-width: 800px) {
   article {
      /* css for browsers with width ā‰¤ 800px */
      }
 }
@media screen and (max-width: 400px) {
   article {
      /* css for browsers with width ā‰¤ 400px */
      }
 }
@media screen and (max-width: 400px) {
     article {
        /* css for browsers with width ā‰¤ 400px */
        }
   }


Remember that mobile browsers have a
default viewport width (e.g. 850px).
For your mobile speciļ¬c media queries
to work, you need to set the viewport!
default viewport.     width=device-width.
mobile speciļ¬c media    mobile speciļ¬c media
 queries not applied.     queries applied.
The viewport and media queries
combo allows you to create just
one responsive site that works
everywhere.
Q: What about max/min-device-width/height?

A: There are use cases for this, but note that your
media queries wonā€™t be applied when resizing the
browser on desktop.
Q: Should I start from small to large, or vice versa?

A: Do mobile ļ¬rst, then enhance for desktop. This
will make the mobile experience faster. Deal with
old IE using a polyļ¬ll, such as Respond.js
                               https://github.com/scottjehl/Respond
Q: Which screen sizes should I design for?

A: All of them! No, seriously, donā€™t limit yourself.
Resize your browser window and tweak different
elementsā€™ CSS properties when needed.
http://www.ļ¬‚ickr.com/photos/33284937@N04/5445675024/
Dealing with
high-DPI screens
A pixel is not what it seems
Thus far, weā€™ve talked about
pixels in terms of ā€œCSS pixelsā€.
One CSS pixel can be multiple
device pixels.
HVGA portrait




almost WVGA portrait
HVGA portrait




almost WVGA portrait
almost WVGA portrait
Device is 480px
wide, but browser
applies default
zoom of 150%.

480px/1.5 = 320px
In most scenarios, you wonā€™t
have to worry about this.
It just works.
However, if you want to
control DPI related stuff,
these are the things you can do:
almost WVGA portrait
(1)
Use high resolution
images to preserve
crispiness.
almost WVGA portrait
(2)
Use the device-
pixel-ratio media
query to serve
DPI-speciļ¬c CSS.
almost WVGA portrait
Iā€™ve set the
1500Ɨ1500px
background-image
to repeat every
1000px, making it
crispy again. The
rest of the content is
still scaled 150%.
NB:
-o-max/min-device-pixel-ratio uses fractions
-webkit-max/min-device-pixel-ratio uses numbers
almost WVGA portrait
(3)
Set the meta
viewportā€™s target-
densitydpi property
to device-dpi.
almost WVGA portrait
(3)
Everything is shown
at 100%. One CSS
pixel is equal to one
device pixel.
NB:
There are other target-densitydpi values, such as
high-dpi, medium-dpi, low-dpi, as well as actual DPI
numbers, but donā€™t bother with them. Just use
device-dpi, and then only if really needed.
http://www.ļ¬‚ickr.com/photos/33284937@N04/5588693890/
@viewport
CSS Device Adaptation ED
Why doing all this viewport
stuff with <meta> tags? Isnā€™t
this something for CSS?
<meta name="viewport" content="width=device-
width, initial-scale=1, user-scalable=no">

becomes

@viewport {
  width: device-width;
  zoom: 1;
  user-zoom: ļ¬xed;
}
<meta name="viewport" content="width=device-
width, initial-scale=1, user-scalable=no">

becomes

@-o-viewport {
  width: device-width;
  zoom: 1;
  user-zoom: ļ¬xed;
}
@-o-viewport {
  width: device-width;
}
@media screen and (max-device-width: 480px) {
  @-o-viewport {
    width: 480px;
  }
}
Craz
                                       y stu
                                            ff
@-o-viewport {
  width: device-width;
}
@media screen and (max-device-width: 480px) {
  @-o-viewport {
    width: 480px;
  }
}
Phew, that was all!
Thanks for listening :-)
                    @andreasbovens


Thanks to ~yc for the wooden background: http://yc.deviantart.com/art/Wood-Rays-62468397

More Related Content

Viewers also liked

Introduction marketing-industriel
Introduction marketing-industrielIntroduction marketing-industriel
Introduction marketing-industrielMĆ©moire MĆ©moire
Ā 
Video marketing en B2B - Outil de Content Marketing
Video marketing en B2B - Outil de Content MarketingVideo marketing en B2B - Outil de Content Marketing
Video marketing en B2B - Outil de Content MarketingChristelle Austruy
Ā 
9 tips to boost your innovation project (by @nickdemey @boardofinno)
9 tips to boost your innovation project (by @nickdemey @boardofinno)9 tips to boost your innovation project (by @nickdemey @boardofinno)
9 tips to boost your innovation project (by @nickdemey @boardofinno)Board of Innovation
Ā 
Sniffer for detecting lost mobiles
Sniffer for detecting lost mobilesSniffer for detecting lost mobiles
Sniffer for detecting lost mobilesAbhishek Abhi
Ā 
Sniffer for detecting lost mobiles
Sniffer for detecting lost mobilesSniffer for detecting lost mobiles
Sniffer for detecting lost mobilesakhila immadisetty
Ā 
Sniffer for the mobile phones
Sniffer for the mobile phonesSniffer for the mobile phones
Sniffer for the mobile phonesUpender Upr
Ā 
Axure for dummies, that don't even know they are
Axure for dummies, that don't even know they areAxure for dummies, that don't even know they are
Axure for dummies, that don't even know they areOscar Gonzalez Garza
Ā 
How to deal with tech media by @mikebutcher
How to deal with tech media by @mikebutcherHow to deal with tech media by @mikebutcher
How to deal with tech media by @mikebutchermikebutcher
Ā 
Sniffer for Detecting Lost Mobile
Sniffer for Detecting Lost MobileSniffer for Detecting Lost Mobile
Sniffer for Detecting Lost MobileSeminar Links
Ā 
Sniffer for detecting lost mobile ppt
Sniffer for detecting lost mobile pptSniffer for detecting lost mobile ppt
Sniffer for detecting lost mobile pptasmita tarar
Ā 
Responsive Design with Axure 7.0ā€™s Adaptive Views
Responsive Design with Axure 7.0ā€™s Adaptive ViewsResponsive Design with Axure 7.0ā€™s Adaptive Views
Responsive Design with Axure 7.0ā€™s Adaptive ViewsSvetlin Denkov
Ā 
How to Extend Axure's Animation Capability
How to Extend Axure's Animation CapabilityHow to Extend Axure's Animation Capability
How to Extend Axure's Animation CapabilitySvetlin Denkov
Ā 
Best Of Marketing B2B 2011
Best Of Marketing B2B 2011Best Of Marketing B2B 2011
Best Of Marketing B2B 2011Leadforce
Ā 

Viewers also liked (15)

Introduction marketing-industriel
Introduction marketing-industrielIntroduction marketing-industriel
Introduction marketing-industriel
Ā 
Video marketing en B2B - Outil de Content Marketing
Video marketing en B2B - Outil de Content MarketingVideo marketing en B2B - Outil de Content Marketing
Video marketing en B2B - Outil de Content Marketing
Ā 
9 tips to boost your innovation project (by @nickdemey @boardofinno)
9 tips to boost your innovation project (by @nickdemey @boardofinno)9 tips to boost your innovation project (by @nickdemey @boardofinno)
9 tips to boost your innovation project (by @nickdemey @boardofinno)
Ā 
Sniffer for detecting lost mobiles
Sniffer for detecting lost mobilesSniffer for detecting lost mobiles
Sniffer for detecting lost mobiles
Ā 
Things to Watch: Music Edition (October 2011)
Things to Watch: Music Edition (October 2011)Things to Watch: Music Edition (October 2011)
Things to Watch: Music Edition (October 2011)
Ā 
Sniffer for detecting lost mobiles
Sniffer for detecting lost mobilesSniffer for detecting lost mobiles
Sniffer for detecting lost mobiles
Ā 
Sniffer for the mobile phones
Sniffer for the mobile phonesSniffer for the mobile phones
Sniffer for the mobile phones
Ā 
Axure for dummies, that don't even know they are
Axure for dummies, that don't even know they areAxure for dummies, that don't even know they are
Axure for dummies, that don't even know they are
Ā 
Sniffer ppt
Sniffer pptSniffer ppt
Sniffer ppt
Ā 
How to deal with tech media by @mikebutcher
How to deal with tech media by @mikebutcherHow to deal with tech media by @mikebutcher
How to deal with tech media by @mikebutcher
Ā 
Sniffer for Detecting Lost Mobile
Sniffer for Detecting Lost MobileSniffer for Detecting Lost Mobile
Sniffer for Detecting Lost Mobile
Ā 
Sniffer for detecting lost mobile ppt
Sniffer for detecting lost mobile pptSniffer for detecting lost mobile ppt
Sniffer for detecting lost mobile ppt
Ā 
Responsive Design with Axure 7.0ā€™s Adaptive Views
Responsive Design with Axure 7.0ā€™s Adaptive ViewsResponsive Design with Axure 7.0ā€™s Adaptive Views
Responsive Design with Axure 7.0ā€™s Adaptive Views
Ā 
How to Extend Axure's Animation Capability
How to Extend Axure's Animation CapabilityHow to Extend Axure's Animation Capability
How to Extend Axure's Animation Capability
Ā 
Best Of Marketing B2B 2011
Best Of Marketing B2B 2011Best Of Marketing B2B 2011
Best Of Marketing B2B 2011
Ā 

More from Andreas Bovens

Progressive Web Apps: Opera's perspective
Progressive Web Apps: Opera's perspectiveProgressive Web Apps: Opera's perspective
Progressive Web Apps: Opera's perspectiveAndreas Bovens
Ā 
Intro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresIntro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresAndreas Bovens
Ā 
Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...Andreas Bovens
Ā 
Fast & Furious: Speed in the Opera browser
Fast & Furious: Speed in the Opera browserFast & Furious: Speed in the Opera browser
Fast & Furious: Speed in the Opera browserAndreas Bovens
Ā 
SVG in Operaā€™s desktop, mobile & TV browsers ā€” edition 2011
SVG in Operaā€™s desktop, mobile & TV browsers  ā€” edition 2011SVG in Operaā€™s desktop, mobile & TV browsers  ā€” edition 2011
SVG in Operaā€™s desktop, mobile & TV browsers ā€” edition 2011Andreas Bovens
Ā 
Building rich apps with HTML5 and friends
Building rich apps with HTML5 and friendsBuilding rich apps with HTML5 and friends
Building rich apps with HTML5 and friendsAndreas Bovens
Ā 
SVG in the Opera browser
SVG in the Opera browserSVG in the Opera browser
SVG in the Opera browserAndreas Bovens
Ā 
Mobile web development techniques (and Opera's developer tools)
Mobile web development techniques (and Opera's developer tools)Mobile web development techniques (and Opera's developer tools)
Mobile web development techniques (and Opera's developer tools)Andreas Bovens
Ā 
Opera and the Open Web platform
Opera and the Open Web platformOpera and the Open Web platform
Opera and the Open Web platformAndreas Bovens
Ā 
Opera Widgets for Desktop and Opera Dragonfly
Opera Widgets for Desktop and Opera DragonflyOpera Widgets for Desktop and Opera Dragonfly
Opera Widgets for Desktop and Opera DragonflyAndreas Bovens
Ā 

More from Andreas Bovens (10)

Progressive Web Apps: Opera's perspective
Progressive Web Apps: Opera's perspectiveProgressive Web Apps: Opera's perspective
Progressive Web Apps: Opera's perspective
Ā 
Intro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresIntro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS features
Ā 
Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...
Ā 
Fast & Furious: Speed in the Opera browser
Fast & Furious: Speed in the Opera browserFast & Furious: Speed in the Opera browser
Fast & Furious: Speed in the Opera browser
Ā 
SVG in Operaā€™s desktop, mobile & TV browsers ā€” edition 2011
SVG in Operaā€™s desktop, mobile & TV browsers  ā€” edition 2011SVG in Operaā€™s desktop, mobile & TV browsers  ā€” edition 2011
SVG in Operaā€™s desktop, mobile & TV browsers ā€” edition 2011
Ā 
Building rich apps with HTML5 and friends
Building rich apps with HTML5 and friendsBuilding rich apps with HTML5 and friends
Building rich apps with HTML5 and friends
Ā 
SVG in the Opera browser
SVG in the Opera browserSVG in the Opera browser
SVG in the Opera browser
Ā 
Mobile web development techniques (and Opera's developer tools)
Mobile web development techniques (and Opera's developer tools)Mobile web development techniques (and Opera's developer tools)
Mobile web development techniques (and Opera's developer tools)
Ā 
Opera and the Open Web platform
Opera and the Open Web platformOpera and the Open Web platform
Opera and the Open Web platform
Ā 
Opera Widgets for Desktop and Opera Dragonfly
Opera Widgets for Desktop and Opera DragonflyOpera Widgets for Desktop and Opera Dragonfly
Opera Widgets for Desktop and Opera Dragonfly
Ā 

Recently uploaded

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
Ā 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
Ā 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
Ā 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
Ā 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
Ā 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
Ā 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Ā 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Ā 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Ā 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 

Optimizing your layout for phones and tablets using viewport and media queries

  • 1. Optimizing your layout for phones and tablets using viewport and media queries Andreas Bovens - Opera Software
  • 2. about me http://www.ļ¬‚ickr.com/pho tos/thomaaas/4783952591 /
  • 3. about me http://www.ļ¬‚ickr.com/pho tos/thomaaas/4783952591 /
  • 4. about me http://www.ļ¬‚ickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.ļ¬‚ickr.c
  • 5. about me http://www.ļ¬‚ickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.ļ¬‚ickr.c
  • 6. about me http://www.ļ¬‚ickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.ļ¬‚ickr.c http://www.ļ¬‚ickr.com/photos/forcery/ 3511170176/
  • 7. Bruce Lawson Daniel Davis Divya Manian Chris Mills Karl Dubost Shwetank Dixit Tiffany Brown Andreas Bovens Luz Caballero Patrick Lauke Zi Bin Cheah Vadim Makeev Mike Taylor
  • 8. ā€œPatterns for Multiscreen Strategiesā€ Coherence Syncronization Screen sharing By Precious http://slidesha.re/kiip5y Device shifting Complementarity Simultaneity These patterns should help understand and define strategies for the multiscreen world.
  • 9. Coherence Syncronization Screen sharing Device shifting Complementarity Simultaneity These patterns should help understand and define strategies for the multiscreen world. http://slidesha.re/kiip5y
  • 10. ā€œA digital product or service looks and works coherently across devices. Features are optimized for speciļ¬c device characteristics and usage scenarios.ā€ Coherence http://slidesha.re/kiip5y
  • 11. Coherence http://slidesha.re/kiip5y
  • 12. ?
  • 14.
  • 15.
  • 16. small screen rendering aka single column view
  • 17.
  • 18.
  • 19.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Thatā€™s all nice, but what if I want to control this zooming behavior?
  • 30.
  • 31. This is the viewport
  • 33. Most commonly though, youā€™ll want to focus on controlling page width...
  • 34. <meta ...> ... using a "viewport" meta tag in the <head> of the page.
  • 35. works in: with some exceptions ;-)
  • 39. HVGA portrait no viewport deļ¬ned in <head>, so fallback to default of 850px, which is squeezed inside 320px.
  • 40. HVGA portrait <meta name="viewport" content="width=320">
  • 41. HVGA portrait <meta name="viewport" content="width=320">
  • 42. HVGA portrait HVGA landscape <meta name="viewport" content="width=320">
  • 43. HVGA portrait <meta name="viewport" content="width=device-width">
  • 44. HVGA portrait <meta name="viewport" content="width=device-width">
  • 45. HVGA portrait HVGA landscape <meta name="viewport" content="width=device-width">
  • 46. HVGA landscape HVGA landscape 480px 320px Ɨ 1.5 zoom
  • 47. HVGA landscape HVGA landscape 480px 320px Ɨ 1.5 zoom
  • 48. HVGA portrait <meta name="viewport" content="initial-scale=1">
  • 49. HVGA portrait <meta name="viewport" content="initial-scale=1">
  • 50. HVGA portrait HVGA landscape <meta name="viewport" content="initial-scale=1">
  • 51. HVGA portrait HVGA landscape <meta name="viewport" content="initial-scale=1"> (same result as width=device-width)
  • 52. HVGA portrait HVGA landscape <meta name="viewport" content="initial-scale=0.5">
  • 53. HVGA portrait HVGA landscape <meta name="viewport" content="initial-scale=2">
  • 55. HVGA portrait <meta name="viewport" content="width=device-width"> + <div style="width: 600px">
  • 56. HVGA portrait <meta name="viewport" content="width=device-width, initial-scale=1"> + <div style="width: 600px">
  • 57. other stuff maximum-scale=... , minimum-scale=... <meta name="viewport" content="initial-scale=1, maximum-scale=1.5"> user-scalable=yes|no <meta name="viewport" content="width=320, user-scalable=no"> height=... <meta name="viewport" content="height=device-height">
  • 58. other stuff maximum-scale=... , minimum-scale=... <meta name="viewport" content="initial-scale=1, maximum-scale=1.5"> user-scalable=yes|no <meta name="viewport" content="width=320, user-scalable=no"> height=... <meta name="viewport" content="height=device-height">
  • 59. other stuff maximum-scale=... , minimum-scale=... <meta name="viewport" content="initial-scale=1, maximum-scale=1.5"> user-scalable=yes|no <meta name="viewport" content="width=320, user-scalable=no"> height=... <meta name="viewport" content="height=device-height">
  • 60. other stuff maximum-scale=... , minimum-scale=... <meta name="viewport" content="initial-scale=1, maximum-scale=1.5"> user-scalable=yes|no <meta name="viewport" content="width=320, user-scalable=no"> height=... <meta name="viewport" content="height=device-height">
  • 61. NB: Make sure to use commas, not semi-colons as delimiters between viewport values! Remember this, especially when syntax-googling ;-)
  • 63. So, how to use this? Snifļ¬ng for mobile browsers maybe?
  • 64. So, how to use this? Snifļ¬ng for mobile browsers maybe? Better donā€™t sniff.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72. Opera/9.80 (Macintosh; Intel Mac OS X 10.5.8; U; en) Presto/2.9.220 Version/12.00
  • 73. Opera/9.80 (Macintosh; Intel Mac OS X 10.5.8; U; en) Presto/2.9.220 Version/12.00
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. So, avoid snifļ¬ng, but if you really have to, provide a way for users to make corrections.
  • 79. So, avoid snifļ¬ng, but if you really have to*, provide a way for users to make corrections. * always ask yourself why the mobile site should be different from the desktop site
  • 80. * always ask yourself why the mobile site should be different from the desktop site customer requir ements tim e restrictions budget limitations capabilities are different different layout needed
  • 81. * always ask yourself why the mobile site should be different from the desktop site customer requir ements tim e restrictions budget limitations capabilities are different different layout needed capability detection
  • 82. * always ask yourself why the mobile site should be different from the desktop site customer requir ements tim e restrictions budget limitations capabilities are different different layout needed capability detection viewport + media queries
  • 83. Letā€™s talk about viewport + media queries media queries
  • 84. Media queries are conditional hooks for applying different CSS rules, depending on e.g. browser width, screen height, aspect ratio, etc.
  • 85. Differently said, media queries allow you to optimize your site layout for all kinds of form factors. Via http://mediaqueri.es/
  • 86. @media screen and (min-width: 400px) { article { border: 5px solid hsla(32, 98%, 51%, 1); box-shadow: hsla(0, 100%, 0%, 0.5) 0 0 10px; max-width: 800px; margin: 0 auto 0 auto; } }
  • 87. @media screen and (min-width: 400px) and (max-width: 800px) { article { /* css for browsers with width ā‰„ 400px and ā‰¤ 800px */ } }
  • 88. @media screen and (min-width: 400px), not projection and (aspect-ratio: 16/9) { article { /* css for browsers with width ā‰„ 400px, except projectors with 16/9 aspect ratio */ } }
  • 89. @media screen and (max-width: 800px) { article { /* css for browsers with width ā‰¤ 800px */ } } @media screen and (max-width: 400px) { article { /* css for browsers with width ā‰¤ 400px */ } }
  • 90. @media screen and (max-width: 400px) { article { /* css for browsers with width ā‰¤ 400px */ } } Remember that mobile browsers have a default viewport width (e.g. 850px). For your mobile speciļ¬c media queries to work, you need to set the viewport!
  • 91.
  • 92. default viewport. width=device-width. mobile speciļ¬c media mobile speciļ¬c media queries not applied. queries applied.
  • 93. The viewport and media queries combo allows you to create just one responsive site that works everywhere.
  • 94.
  • 95. Q: What about max/min-device-width/height? A: There are use cases for this, but note that your media queries wonā€™t be applied when resizing the browser on desktop.
  • 96. Q: Should I start from small to large, or vice versa? A: Do mobile ļ¬rst, then enhance for desktop. This will make the mobile experience faster. Deal with old IE using a polyļ¬ll, such as Respond.js https://github.com/scottjehl/Respond
  • 97. Q: Which screen sizes should I design for? A: All of them! No, seriously, donā€™t limit yourself. Resize your browser window and tweak different elementsā€™ CSS properties when needed.
  • 100. A pixel is not what it seems Thus far, weā€™ve talked about pixels in terms of ā€œCSS pixelsā€. One CSS pixel can be multiple device pixels.
  • 103. almost WVGA portrait Device is 480px wide, but browser applies default zoom of 150%. 480px/1.5 = 320px
  • 104. In most scenarios, you wonā€™t have to worry about this. It just works.
  • 105. However, if you want to control DPI related stuff, these are the things you can do:
  • 106. almost WVGA portrait (1) Use high resolution images to preserve crispiness.
  • 107.
  • 108. almost WVGA portrait (2) Use the device- pixel-ratio media query to serve DPI-speciļ¬c CSS.
  • 109. almost WVGA portrait Iā€™ve set the 1500Ɨ1500px background-image to repeat every 1000px, making it crispy again. The rest of the content is still scaled 150%.
  • 110.
  • 112. almost WVGA portrait (3) Set the meta viewportā€™s target- densitydpi property to device-dpi.
  • 113. almost WVGA portrait (3) Everything is shown at 100%. One CSS pixel is equal to one device pixel.
  • 114.
  • 115. NB: There are other target-densitydpi values, such as high-dpi, medium-dpi, low-dpi, as well as actual DPI numbers, but donā€™t bother with them. Just use device-dpi, and then only if really needed.
  • 118. Why doing all this viewport stuff with <meta> tags? Isnā€™t this something for CSS?
  • 119.
  • 120. <meta name="viewport" content="width=device- width, initial-scale=1, user-scalable=no"> becomes @viewport { width: device-width; zoom: 1; user-zoom: ļ¬xed; }
  • 121. <meta name="viewport" content="width=device- width, initial-scale=1, user-scalable=no"> becomes @-o-viewport { width: device-width; zoom: 1; user-zoom: ļ¬xed; }
  • 122. @-o-viewport { width: device-width; } @media screen and (max-device-width: 480px) { @-o-viewport { width: 480px; } }
  • 123. Craz y stu ff @-o-viewport { width: device-width; } @media screen and (max-device-width: 480px) { @-o-viewport { width: 480px; } }
  • 124. Phew, that was all! Thanks for listening :-) @andreasbovens Thanks to ~yc for the wooden background: http://yc.deviantart.com/art/Wood-Rays-62468397