SlideShare ist ein Scribd-Unternehmen logo
1 von 124
Downloaden Sie, um offline zu lesen
Optimizing your layout
for phones and tablets
using viewport and
media queries
Andreas Bovens - Opera Software
about me




           http://www.flickr.com/pho
                                   tos/thomaaas/4783952591
                                                          /
about me




           http://www.flickr.com/pho
                                   tos/thomaaas/4783952591
                                                          /
about me




                                                             http://www.flickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.flickr.c
about me




                                                             http://www.flickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.flickr.c
about me




                                                             http://www.flickr.com/pho
                                                                                     tos/thomaaas/4783952591
                                                                                                            /




                                          ccio1/119626133/
                          om/photos/bocca
       http://www.flickr.c




                                                                                                               http://www.flickr.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 specific 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 defined 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.flickr.com/photos/33284937@N04/4771132618/
So, how to use this?
Sniffing for mobile
browsers maybe?
So, how to use this?
Sniffing 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 sniffing,
but if you really have to,
provide a way for users
to make corrections.
So, avoid sniffing,
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 specific media queries
to work, you need to set the viewport!
default viewport.     width=device-width.
mobile specific media    mobile specific 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 first, then enhance for desktop. This
will make the mobile experience faster. Deal with
old IE using a polyfill, 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.flickr.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-specific 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.flickr.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: fixed;
}
<meta name="viewport" content="width=device-
width, initial-scale=1, user-scalable=no">

becomes

@-o-viewport {
  width: device-width;
  zoom: 1;
  user-zoom: fixed;
}
@-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

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

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.flickr.com/pho tos/thomaaas/4783952591 /
  • 3. about me http://www.flickr.com/pho tos/thomaaas/4783952591 /
  • 4. about me http://www.flickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.flickr.c
  • 5. about me http://www.flickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.flickr.c
  • 6. about me http://www.flickr.com/pho tos/thomaaas/4783952591 / ccio1/119626133/ om/photos/bocca http://www.flickr.c http://www.flickr.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 specific 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 defined 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? Sniffing for mobile browsers maybe?
  • 64. So, how to use this? Sniffing 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 sniffing, but if you really have to, provide a way for users to make corrections.
  • 79. So, avoid sniffing, 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 specific media queries to work, you need to set the viewport!
  • 91.
  • 92. default viewport. width=device-width. mobile specific media mobile specific 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 first, then enhance for desktop. This will make the mobile experience faster. Deal with old IE using a polyfill, 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-specific 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: fixed; }
  • 121. <meta name="viewport" content="width=device- width, initial-scale=1, user-scalable=no"> becomes @-o-viewport { width: device-width; zoom: 1; user-zoom: fixed; }
  • 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