SlideShare una empresa de Scribd logo
1 de 69
Descargar para leer sin conexión
Adapt!
                        MEDIA QUERIES AND VIEWPORT
  1.
Tuesday, 31 July 2012
Hi — I’m Chris Mills!
              Open standards advocate and Education agitator
              dev.opera.com editor
              W3C web education community group chair
              Accessibility whiner
              HTML5/CSS3 wrangler
              Heavy metal drummer and proud dad


 2.
Tuesday, 31 July 2012
3.
Tuesday, 31 July 2012
Useful Stuff
              dev.opera.com
              slideshare.net/chrisdavidmills
              cmills@opera.com
              @chrisdavidmills




 4.
Tuesday, 31 July 2012
Context For
 5.
           Adaptive Design
Tuesday, 31 July 2012
Adaptive
              “Able to be easily modified to suit a new
              purpose or situation”




 6.
Tuesday, 31 July 2012
Responsive
              “Reacting quickly and positively.”




 7.
Tuesday, 31 July 2012
RWD/AWD
              “Designing sites that will dynamically adapt
              their layout, graphics and other features to suit
              different browsers and devices.”


              Responsive design? Adaptive design? It
              matters not which term you use.


 8.
Tuesday, 31 July 2012
Responsive Web
                        Design is Hot!!




 9.
Tuesday, 31 July 2012
Three Options for creating
          tailored displays
              1. Adapt a single site
              2. Do nothing
              3. Create a separate site/separate sites




 10.
Tuesday, 31 July 2012
Creating separate sites
              Usually a terrible idea
              Despite what “that Nielsen bloke” says
              Maintenance nightmare
              Multiple codebases
              Browser sniffing
              And how many do you have to make?

  11.
Tuesday, 31 July 2012
Doing nothing
              Actually goes a long way
              The web is responsive by default
              Mobile browsers have features to help render
              desktop sites




 12.
Tuesday, 31 July 2012
Adapt a single site
              By far the best option, usually
              Let’s see how!




 13.
Tuesday, 31 July 2012
Adaptive

                        technologies
  14.
Tuesday, 31 July 2012
Adaptive Bread
                          and Butter
              Liquid layouts
              Media types
              Media queries
              Viewport
              Adaptive images

 15.
Tuesday, 31 July 2012
Media Types
              The idea of adaptive design isn’t new
              Media types have been around since CSS2


                        media="screen"
                        media="print"



 16.
Tuesday, 31 July 2012
Media Types
                        media="handheld"
                        media="tv"




 17.
Tuesday, 31 July 2012
Small TV Rant
              “Searching, browsing, updating and
              buffering are not TV-like. In fact an enormous
              number of people found that the technology
              they had purchased wasn't what they
              expected at all, that they were bringing the
              worst parts of using a computer into the
              television environment.”
                   -- www.insideci.co.uk/news/rovi-research-reveals-
 18.                                 changing-consumer-habits.aspx
Tuesday, 31 July 2012
19.
Tuesday, 31 July 2012
Media Types Failed
              Because they make too many assumptions
              And don’t give enough control
              Devs used “handheld” to serve crap dumbed
              down experiences to mobile
              “handheld”, “tv” and “projection” are really
              just “screen”


 20.
Tuesday, 31 July 2012
Media Queries &
 21.
            Viewport
Tuesday, 31 July 2012
Media Queries
              ...succeed where media types failed, mostly
              www.w3.org/TR/css3-mediaqueries/
              Build on top of media types
              Allow more granular control of style
              application
              See mediaqueri.es for tonnes of examples

 22.
Tuesday, 31 July 2012
Basic Media Query
              media="screen and (max-width: 480px)"


              @media screen and (max-width: 480px) {
                        /* Insert rules for
                           narrow screens here */
              }



 23.
Tuesday, 31 July 2012
24.
Tuesday, 31 July 2012
Adding extra conditions
              @media screen and (min-width: 480px) and
              (max-width: 1024px) {
                        /* Rules to be applied between
                           480 and 1024 pixels */
              }




 25.
Tuesday, 31 July 2012
Multiple right answers
              @media screen and (max-width: 1024px),
                     print and (max-width: 21cm) {
                        /* Rules to be applied if either of
                           the two queries are true */
              }




 26.
Tuesday, 31 July 2012
Media Query negation
              @media not screen and (max-width: 480px)
              {
                        /* Rules to be applied when the
                           screen is NOT narrow */
              }




 27.
Tuesday, 31 July 2012
Exclusive Queries
              @media only screen and (max-width:
              480px) {
                        /* An exclusive set of rules,
                           ONLY for narrow screens */
              }




 28.
Tuesday, 31 July 2012
Typical stylesheet
              /* Default styles here */
              @media screen and (min-width: 1400px) {}
              @media screen and (max-width: 800px) {}
              @media screen and (max-width: 480px) {}
              @media screen and (max-width: 320px) {}




 29.
Tuesday, 31 July 2012
Breakpoints
              Where do you need to change your styles?
              Device breakpoint: change styles for specific
              target device screen sizes
              Content breakpoint: changes styles at the
              point where your layout actually breaks



 30.
Tuesday, 31 July 2012
Which way do you do it?
              For a general web site, content breakpoints
              For a platform-targetted app, device
              breakpoints
              More realistically, you’ll do a combination, eg
              fluid width for wide screens, a fixed width
              and height for iPad portrait/landscape, and a
              fluid width for smartphones and other
              devices.
 31.
Tuesday, 31 July 2012
The different available
                       Media Queries
                            width          color
                           height       color-index
                        device-width    monochrome
                        device-height   resolution
                         orientation       scan
                        aspect-ratio       grid
                            device-aspect-ratio
 32.
Tuesday, 31 July 2012
You will most commonly use
              width (and height): this is viewport w/h!
              You could use device-width/height for
              mobiles/tablets, but this confuses things.
              There is a better way (see later)
              resolution: for high fidelity devices
              orientation: for landscape/portrait layout
              optimization (an iPad app, for example)
 33.
Tuesday, 31 July 2012
Beware! Mobiles lie!
                        Want this...   ...Got this?




 34.
Tuesday, 31 July 2012
Mobiles lie...
              They assume a wider viewport than they
              really have
              Render the site at that width
              Then shrink the result to fit on the screen
              For example, Opera Mobile uses 980px



 35.
Tuesday, 31 July 2012
Viewport
              Invented by Apple
              A meta tag
              Suggests initial viewport, zoom, and
              resolution




 36.
Tuesday, 31 July 2012
Viewport example
              <meta name="viewport"
              content="width=device-width">




 37.
Tuesday, 31 July 2012
Much better!




 38.
Tuesday, 31 July 2012
Another common use
              <meta name="viewport"
              content="width=550">




 39.
Tuesday, 31 July 2012
40.
Tuesday, 31 July 2012
Different available
                         Viewport options
                           width         height

                        minimum-scale maximum-scale

                        initial-scale user-scalable

                             target-densitydpi


 41.
Tuesday, 31 July 2012
CSS Device Adaptation
              Viewport = more of a style thing than a
              content thing
              Provides @viewport at-rule to contain
              viewport info
              Supported in Opera and IE10, with prefixes
              dev.opera.com/articles/view/an-introduction-
              to-meta-viewport-and-viewport
 42.
Tuesday, 31 July 2012
CSS Device Adaptation
              <meta name="viewport"
                        content="width=550,
                        maximum-scale=1.0,
                        target-densitydpi=device-dpi">


              @viewport { width: 550px; max-zoom: 1;
                          resolution: device; }

 43.
Tuesday, 31 July 2012
Other Responsive
  Web Design Issues

 44.
Tuesday, 31 July 2012
What else have we got to
              worry about?
              Responsive replaced elements
              Bandwidth/loading of resources
              Resolution
              Processing power
              Control mechanisms

 45.
Tuesday, 31 July 2012
Replaced elements




 46.
Tuesday, 31 July 2012
Replaced elements
              #related img {
                        display: block;
                        margin: 0 auto;
                        max-width: 100%;
              }




 47.
Tuesday, 31 July 2012
Be warned
              Old IE versions don’t support max-width, so
              you’ll have to fallback to width: 100%
              instead.




 48.
Tuesday, 31 July 2012
File size also important
              Users on slow connections won’t want to
              download huge media files.
              We need to try to serve them smaller files/
              alternatives.
              Assumptions: e.g. narrow equals mobile
              equals slow connection


 49.
Tuesday, 31 July 2012
CSS resources easy
                           to deal with
              Use “mobile first”
              Load smaller resources by default, and larger
              ones inside MQs
              Saves narrow screen devices from loading
              wide screen resources


 50.
Tuesday, 31 July 2012
“Mobile first” stylesheet
              /* Default styles here */
              @media screen and (min-width: 320px) {}
              @media screen and (min-width: 480px) {}
              @media screen and (min-width: 800px) {}
              @media screen and (min-width: 1400px) {}




 51.
Tuesday, 31 July 2012
“Mobile first” example
              header { background: url(small-
              image.png); }


              @media screen and (min-width: 480px) {
                header { background: url(large-
              image.png); }
              }


 52.
Tuesday, 31 July 2012
“Mobile first” problems
              IE 6-8 left with mobile layout, as they don’t
              support media queries
              You’ll need to polyfill media queries, e.g. with
              respond.js




 53.
Tuesday, 31 July 2012
HTML5 <video> well served
                  <source src="crystal320.webm"
              type="video/webm" media="all and (max-
              width: 480px)">
                  <source src="crystal720.webm"
              type="video/webm" media="all and (min-
              width: 481px)">




 54.
Tuesday, 31 July 2012
<img> not so lucky
              http://dev.opera.com/articles/view/
              responsive-images-problem/
              None work perfectly
              Pre-fetch is a bitch




 55.
Tuesday, 31 July 2012
adaptive-images.com
              Add .htaccess and adaptive-images.php to
              your document root folder.
              Add one line of JavaScript into the <head> of
              your site.
              Add your CSS Media Query values into
              $resolutions in the PHP file.


 56.
Tuesday, 31 July 2012
The <picture> element
              <picture alt="a picture of something">
                <source src="mobile.jpg">
                <source src="medium.jpg" media="min
                        width: 600px">
                <source src="fullsize.jpg" media="min
                        width: 900px">
                <img src="mobile.jpg">
              </picture>

 57.
Tuesday, 31 July 2012
The srcset attribute
              <img src="face-600-200-at-1.jpeg" alt=""
              srcset="face-600-200-at-1.jpeg 600w 200h
              1x, face-600-200-at-2.jpeg 600w 200h 2x,
              face-icon.png 200w 200h">




 58.
Tuesday, 31 July 2012
Processing power
              You might want to turn off effects like
              shadows, gradients and animations for small
              screen devices
              CSS effects are arguably less power draining
              than JS or Flash, but even so
              They can cause the UI to look cluttered too

 59.
Tuesday, 31 July 2012
Resolution
              Hi-fidelity devices are causing an issue, e.g.
              iPhone 4s is 960 x 640 pixels at 326ppi
              These devices lie twice
              One CSS pixel = multiple device pixels
              Images can start to look pixellated



 60.
Tuesday, 31 July 2012
Solutions
              <img src="500px_image.jpg" width="250">




 61.
Tuesday, 31 July 2012
Solutions
              @media screen and (-o-min-device-pixel-
              ratio: 3/2) {
                        body { background-size: 250px; }
              }
              @media screen and (-webkit-min-device-
              pixel-ratio: 1.5) {
                        body { background-size: 250px; }
              }
 62.
Tuesday, 31 July 2012
63.
Tuesday, 31 July 2012
Soon to be replaced by
              @media screen and (resolution: 1.5dppx)
              {
                        body { background-size: 250px; }
              }




 64.
Tuesday, 31 July 2012
Tell the truth with viewport
              <meta name="viewport"
                        content="width=device-width,
                        target-densitydpi=device-dpi">




 65.
Tuesday, 31 July 2012
All good, but...
              Images may now start to look a little small
              You could serve larger images for devices
              with higher resolutions




 66.
Tuesday, 31 July 2012
Control mechanisms
              Currently tricky
              Usual wisdom about web sites applies: Make
              pages keyboard accessible, etc.
              Can’t be detected in CSS (yet)
              JavaScript touch detection is an option:
              Modernizr, jQuery


 67.
Tuesday, 31 July 2012
“Subtle” advertisment
                 Buy my book
 68.
Tuesday, 31 July 2012
dev.opera.com | cmills@opera.com | @chrisdavidmills




              Thanks!
 69.
Tuesday, 31 July 2012

Más contenido relacionado

Similar a Adapt! Media queries and viewport

Rapid Prototype the User Experience
Rapid Prototype the User ExperienceRapid Prototype the User Experience
Rapid Prototype the User ExperienceHong Qu
 
What is ud demographics-w-notes - adopted for dis stud class
What is ud   demographics-w-notes - adopted for dis stud classWhat is ud   demographics-w-notes - adopted for dis stud class
What is ud demographics-w-notes - adopted for dis stud classHoward Kramer
 
NCDevCon2012_designing the mobile experience
NCDevCon2012_designing the mobile experienceNCDevCon2012_designing the mobile experience
NCDevCon2012_designing the mobile experienceDee Sadler
 
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...Roberto García
 
Typography and Responsive Grids in the World of Mobile Development
Typography and Responsive Grids in the World of Mobile DevelopmentTypography and Responsive Grids in the World of Mobile Development
Typography and Responsive Grids in the World of Mobile DevelopmentTiago Pedras
 
BASIC principles: multimedia journalism and narrative
BASIC principles: multimedia journalism and narrativeBASIC principles: multimedia journalism and narrative
BASIC principles: multimedia journalism and narrativePaul Bradshaw
 
Speed and simplicity
Speed and simplicitySpeed and simplicity
Speed and simplicitymStoner, Inc.
 
Speed and Simplicity: Design and Usability for Multi-device Websites
Speed and Simplicity: Design and Usability for Multi-device WebsitesSpeed and Simplicity: Design and Usability for Multi-device Websites
Speed and Simplicity: Design and Usability for Multi-device WebsitesDoug Gapinski
 
UX-Driven & Inclusive Data Visualizations
UX-Driven & Inclusive Data VisualizationsUX-Driven & Inclusive Data Visualizations
UX-Driven & Inclusive Data VisualizationsMichelle Michael
 
Developing internationally building stuff that works across the world - adobe
Developing internationally   building stuff that works across the world - adobeDeveloping internationally   building stuff that works across the world - adobe
Developing internationally building stuff that works across the world - adobeUgonna William Imoh
 
Designing for Multiple Devices - Sarit Arora
 Designing for Multiple Devices - Sarit Arora Designing for Multiple Devices - Sarit Arora
Designing for Multiple Devices - Sarit AroraSTC India UX SIG
 
Postdesktop Usability
Postdesktop UsabilityPostdesktop Usability
Postdesktop UsabilityDoug Gapinski
 
Screen and Context: Usability in the Postdesktop World
Screen and Context: Usability in the Postdesktop WorldScreen and Context: Usability in the Postdesktop World
Screen and Context: Usability in the Postdesktop WorldDoug Gapinski
 
Basic section b essay structures
Basic section b essay structuresBasic section b essay structures
Basic section b essay structuresMissConnell
 
Designing and evaluating web sites using universal design principles (hands on)
Designing and evaluating web sites using universal design principles (hands on)Designing and evaluating web sites using universal design principles (hands on)
Designing and evaluating web sites using universal design principles (hands on)Howard Kramer
 

Similar a Adapt! Media queries and viewport (20)

Rapid Prototype the User Experience
Rapid Prototype the User ExperienceRapid Prototype the User Experience
Rapid Prototype the User Experience
 
What is ud demographics-w-notes - adopted for dis stud class
What is ud   demographics-w-notes - adopted for dis stud classWhat is ud   demographics-w-notes - adopted for dis stud class
What is ud demographics-w-notes - adopted for dis stud class
 
NCDevCon2012_designing the mobile experience
NCDevCon2012_designing the mobile experienceNCDevCon2012_designing the mobile experience
NCDevCon2012_designing the mobile experience
 
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...
Linked Data: the Entry Point for Worldwide Media Fragments Re-use and Copyrig...
 
Typography and Responsive Grids in the World of Mobile Development
Typography and Responsive Grids in the World of Mobile DevelopmentTypography and Responsive Grids in the World of Mobile Development
Typography and Responsive Grids in the World of Mobile Development
 
BYO3D 2011: Welcome
BYO3D 2011: WelcomeBYO3D 2011: Welcome
BYO3D 2011: Welcome
 
BASIC principles: multimedia journalism and narrative
BASIC principles: multimedia journalism and narrativeBASIC principles: multimedia journalism and narrative
BASIC principles: multimedia journalism and narrative
 
3DPrinting Technologies
3DPrinting Technologies3DPrinting Technologies
3DPrinting Technologies
 
Solidworks
Solidworks Solidworks
Solidworks
 
Digital vs Analogue
Digital vs AnalogueDigital vs Analogue
Digital vs Analogue
 
Speed and simplicity
Speed and simplicitySpeed and simplicity
Speed and simplicity
 
Speed and Simplicity: Design and Usability for Multi-device Websites
Speed and Simplicity: Design and Usability for Multi-device WebsitesSpeed and Simplicity: Design and Usability for Multi-device Websites
Speed and Simplicity: Design and Usability for Multi-device Websites
 
The Design of Everyday Things
The Design of Everyday ThingsThe Design of Everyday Things
The Design of Everyday Things
 
UX-Driven & Inclusive Data Visualizations
UX-Driven & Inclusive Data VisualizationsUX-Driven & Inclusive Data Visualizations
UX-Driven & Inclusive Data Visualizations
 
Developing internationally building stuff that works across the world - adobe
Developing internationally   building stuff that works across the world - adobeDeveloping internationally   building stuff that works across the world - adobe
Developing internationally building stuff that works across the world - adobe
 
Designing for Multiple Devices - Sarit Arora
 Designing for Multiple Devices - Sarit Arora Designing for Multiple Devices - Sarit Arora
Designing for Multiple Devices - Sarit Arora
 
Postdesktop Usability
Postdesktop UsabilityPostdesktop Usability
Postdesktop Usability
 
Screen and Context: Usability in the Postdesktop World
Screen and Context: Usability in the Postdesktop WorldScreen and Context: Usability in the Postdesktop World
Screen and Context: Usability in the Postdesktop World
 
Basic section b essay structures
Basic section b essay structuresBasic section b essay structures
Basic section b essay structures
 
Designing and evaluating web sites using universal design principles (hands on)
Designing and evaluating web sites using universal design principles (hands on)Designing and evaluating web sites using universal design principles (hands on)
Designing and evaluating web sites using universal design principles (hands on)
 

Más de Chris Mills

More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable webChris Mills
 
Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’Chris Mills
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web appsChris Mills
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the futureChris Mills
 
Guerrilla education
Guerrilla educationGuerrilla education
Guerrilla educationChris Mills
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!Chris Mills
 
Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"Chris Mills
 
Documentation and publishing
Documentation and publishingDocumentation and publishing
Documentation and publishingChris Mills
 
Getting rid of images with CSS
Getting rid of images with CSSGetting rid of images with CSS
Getting rid of images with CSSChris Mills
 
Laying out the future
Laying out the futureLaying out the future
Laying out the futureChris Mills
 
Accessibility doesn't exist
Accessibility doesn't existAccessibility doesn't exist
Accessibility doesn't existChris Mills
 
Responsive web design standards?
Responsive web design standards?Responsive web design standards?
Responsive web design standards?Chris Mills
 
HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?Chris Mills
 
HTML5 Pearson preso
HTML5 Pearson presoHTML5 Pearson preso
HTML5 Pearson presoChris Mills
 
Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5Chris Mills
 
Inclusive design: real accessibility for everyone
Inclusive design: real accessibility for everyoneInclusive design: real accessibility for everyone
Inclusive design: real accessibility for everyoneChris Mills
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)Chris Mills
 

Más de Chris Mills (20)

More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable web
 
Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’Feedback handling, community wrangling, panhandlin’
Feedback handling, community wrangling, panhandlin’
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web apps
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the future
 
Guerrilla education
Guerrilla educationGuerrilla education
Guerrilla education
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
BrazilJS MDN
BrazilJS MDNBrazilJS MDN
BrazilJS MDN
 
Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"
 
Documentation and publishing
Documentation and publishingDocumentation and publishing
Documentation and publishing
 
MDN is easy!
MDN is easy!MDN is easy!
MDN is easy!
 
Getting rid of images with CSS
Getting rid of images with CSSGetting rid of images with CSS
Getting rid of images with CSS
 
Future layouts
Future layoutsFuture layouts
Future layouts
 
Laying out the future
Laying out the futureLaying out the future
Laying out the future
 
Accessibility doesn't exist
Accessibility doesn't existAccessibility doesn't exist
Accessibility doesn't exist
 
Responsive web design standards?
Responsive web design standards?Responsive web design standards?
Responsive web design standards?
 
HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?HTML5 and CSS3: does now really mean now?
HTML5 and CSS3: does now really mean now?
 
HTML5 Pearson preso
HTML5 Pearson presoHTML5 Pearson preso
HTML5 Pearson preso
 
Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5
 
Inclusive design: real accessibility for everyone
Inclusive design: real accessibility for everyoneInclusive design: real accessibility for everyone
Inclusive design: real accessibility for everyone
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley 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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
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
 
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
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
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...
 
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
 

Adapt! Media queries and viewport

  • 1. Adapt! MEDIA QUERIES AND VIEWPORT 1. Tuesday, 31 July 2012
  • 2. Hi — I’m Chris Mills! Open standards advocate and Education agitator dev.opera.com editor W3C web education community group chair Accessibility whiner HTML5/CSS3 wrangler Heavy metal drummer and proud dad 2. Tuesday, 31 July 2012
  • 4. Useful Stuff dev.opera.com slideshare.net/chrisdavidmills cmills@opera.com @chrisdavidmills 4. Tuesday, 31 July 2012
  • 5. Context For 5. Adaptive Design Tuesday, 31 July 2012
  • 6. Adaptive “Able to be easily modified to suit a new purpose or situation” 6. Tuesday, 31 July 2012
  • 7. Responsive “Reacting quickly and positively.” 7. Tuesday, 31 July 2012
  • 8. RWD/AWD “Designing sites that will dynamically adapt their layout, graphics and other features to suit different browsers and devices.” Responsive design? Adaptive design? It matters not which term you use. 8. Tuesday, 31 July 2012
  • 9. Responsive Web Design is Hot!! 9. Tuesday, 31 July 2012
  • 10. Three Options for creating tailored displays 1. Adapt a single site 2. Do nothing 3. Create a separate site/separate sites 10. Tuesday, 31 July 2012
  • 11. Creating separate sites Usually a terrible idea Despite what “that Nielsen bloke” says Maintenance nightmare Multiple codebases Browser sniffing And how many do you have to make? 11. Tuesday, 31 July 2012
  • 12. Doing nothing Actually goes a long way The web is responsive by default Mobile browsers have features to help render desktop sites 12. Tuesday, 31 July 2012
  • 13. Adapt a single site By far the best option, usually Let’s see how! 13. Tuesday, 31 July 2012
  • 14. Adaptive technologies 14. Tuesday, 31 July 2012
  • 15. Adaptive Bread and Butter Liquid layouts Media types Media queries Viewport Adaptive images 15. Tuesday, 31 July 2012
  • 16. Media Types The idea of adaptive design isn’t new Media types have been around since CSS2 media="screen" media="print" 16. Tuesday, 31 July 2012
  • 17. Media Types media="handheld" media="tv" 17. Tuesday, 31 July 2012
  • 18. Small TV Rant “Searching, browsing, updating and buffering are not TV-like. In fact an enormous number of people found that the technology they had purchased wasn't what they expected at all, that they were bringing the worst parts of using a computer into the television environment.” -- www.insideci.co.uk/news/rovi-research-reveals- 18. changing-consumer-habits.aspx Tuesday, 31 July 2012
  • 20. Media Types Failed Because they make too many assumptions And don’t give enough control Devs used “handheld” to serve crap dumbed down experiences to mobile “handheld”, “tv” and “projection” are really just “screen” 20. Tuesday, 31 July 2012
  • 21. Media Queries & 21. Viewport Tuesday, 31 July 2012
  • 22. Media Queries ...succeed where media types failed, mostly www.w3.org/TR/css3-mediaqueries/ Build on top of media types Allow more granular control of style application See mediaqueri.es for tonnes of examples 22. Tuesday, 31 July 2012
  • 23. Basic Media Query media="screen and (max-width: 480px)" @media screen and (max-width: 480px) { /* Insert rules for narrow screens here */ } 23. Tuesday, 31 July 2012
  • 25. Adding extra conditions @media screen and (min-width: 480px) and (max-width: 1024px) { /* Rules to be applied between 480 and 1024 pixels */ } 25. Tuesday, 31 July 2012
  • 26. Multiple right answers @media screen and (max-width: 1024px), print and (max-width: 21cm) { /* Rules to be applied if either of the two queries are true */ } 26. Tuesday, 31 July 2012
  • 27. Media Query negation @media not screen and (max-width: 480px) { /* Rules to be applied when the screen is NOT narrow */ } 27. Tuesday, 31 July 2012
  • 28. Exclusive Queries @media only screen and (max-width: 480px) { /* An exclusive set of rules, ONLY for narrow screens */ } 28. Tuesday, 31 July 2012
  • 29. Typical stylesheet /* Default styles here */ @media screen and (min-width: 1400px) {} @media screen and (max-width: 800px) {} @media screen and (max-width: 480px) {} @media screen and (max-width: 320px) {} 29. Tuesday, 31 July 2012
  • 30. Breakpoints Where do you need to change your styles? Device breakpoint: change styles for specific target device screen sizes Content breakpoint: changes styles at the point where your layout actually breaks 30. Tuesday, 31 July 2012
  • 31. Which way do you do it? For a general web site, content breakpoints For a platform-targetted app, device breakpoints More realistically, you’ll do a combination, eg fluid width for wide screens, a fixed width and height for iPad portrait/landscape, and a fluid width for smartphones and other devices. 31. Tuesday, 31 July 2012
  • 32. The different available Media Queries width color height color-index device-width monochrome device-height resolution orientation scan aspect-ratio grid device-aspect-ratio 32. Tuesday, 31 July 2012
  • 33. You will most commonly use width (and height): this is viewport w/h! You could use device-width/height for mobiles/tablets, but this confuses things. There is a better way (see later) resolution: for high fidelity devices orientation: for landscape/portrait layout optimization (an iPad app, for example) 33. Tuesday, 31 July 2012
  • 34. Beware! Mobiles lie! Want this... ...Got this? 34. Tuesday, 31 July 2012
  • 35. Mobiles lie... They assume a wider viewport than they really have Render the site at that width Then shrink the result to fit on the screen For example, Opera Mobile uses 980px 35. Tuesday, 31 July 2012
  • 36. Viewport Invented by Apple A meta tag Suggests initial viewport, zoom, and resolution 36. Tuesday, 31 July 2012
  • 37. Viewport example <meta name="viewport" content="width=device-width"> 37. Tuesday, 31 July 2012
  • 39. Another common use <meta name="viewport" content="width=550"> 39. Tuesday, 31 July 2012
  • 41. Different available Viewport options width height minimum-scale maximum-scale initial-scale user-scalable target-densitydpi 41. Tuesday, 31 July 2012
  • 42. CSS Device Adaptation Viewport = more of a style thing than a content thing Provides @viewport at-rule to contain viewport info Supported in Opera and IE10, with prefixes dev.opera.com/articles/view/an-introduction- to-meta-viewport-and-viewport 42. Tuesday, 31 July 2012
  • 43. CSS Device Adaptation <meta name="viewport" content="width=550, maximum-scale=1.0, target-densitydpi=device-dpi"> @viewport { width: 550px; max-zoom: 1; resolution: device; } 43. Tuesday, 31 July 2012
  • 44. Other Responsive Web Design Issues 44. Tuesday, 31 July 2012
  • 45. What else have we got to worry about? Responsive replaced elements Bandwidth/loading of resources Resolution Processing power Control mechanisms 45. Tuesday, 31 July 2012
  • 47. Replaced elements #related img { display: block; margin: 0 auto; max-width: 100%; } 47. Tuesday, 31 July 2012
  • 48. Be warned Old IE versions don’t support max-width, so you’ll have to fallback to width: 100% instead. 48. Tuesday, 31 July 2012
  • 49. File size also important Users on slow connections won’t want to download huge media files. We need to try to serve them smaller files/ alternatives. Assumptions: e.g. narrow equals mobile equals slow connection 49. Tuesday, 31 July 2012
  • 50. CSS resources easy to deal with Use “mobile first” Load smaller resources by default, and larger ones inside MQs Saves narrow screen devices from loading wide screen resources 50. Tuesday, 31 July 2012
  • 51. “Mobile first” stylesheet /* Default styles here */ @media screen and (min-width: 320px) {} @media screen and (min-width: 480px) {} @media screen and (min-width: 800px) {} @media screen and (min-width: 1400px) {} 51. Tuesday, 31 July 2012
  • 52. “Mobile first” example header { background: url(small- image.png); } @media screen and (min-width: 480px) { header { background: url(large- image.png); } } 52. Tuesday, 31 July 2012
  • 53. “Mobile first” problems IE 6-8 left with mobile layout, as they don’t support media queries You’ll need to polyfill media queries, e.g. with respond.js 53. Tuesday, 31 July 2012
  • 54. HTML5 <video> well served <source src="crystal320.webm" type="video/webm" media="all and (max- width: 480px)"> <source src="crystal720.webm" type="video/webm" media="all and (min- width: 481px)"> 54. Tuesday, 31 July 2012
  • 55. <img> not so lucky http://dev.opera.com/articles/view/ responsive-images-problem/ None work perfectly Pre-fetch is a bitch 55. Tuesday, 31 July 2012
  • 56. adaptive-images.com Add .htaccess and adaptive-images.php to your document root folder. Add one line of JavaScript into the <head> of your site. Add your CSS Media Query values into $resolutions in the PHP file. 56. Tuesday, 31 July 2012
  • 57. The <picture> element <picture alt="a picture of something"> <source src="mobile.jpg"> <source src="medium.jpg" media="min width: 600px"> <source src="fullsize.jpg" media="min width: 900px"> <img src="mobile.jpg"> </picture> 57. Tuesday, 31 July 2012
  • 58. The srcset attribute <img src="face-600-200-at-1.jpeg" alt="" srcset="face-600-200-at-1.jpeg 600w 200h 1x, face-600-200-at-2.jpeg 600w 200h 2x, face-icon.png 200w 200h"> 58. Tuesday, 31 July 2012
  • 59. Processing power You might want to turn off effects like shadows, gradients and animations for small screen devices CSS effects are arguably less power draining than JS or Flash, but even so They can cause the UI to look cluttered too 59. Tuesday, 31 July 2012
  • 60. Resolution Hi-fidelity devices are causing an issue, e.g. iPhone 4s is 960 x 640 pixels at 326ppi These devices lie twice One CSS pixel = multiple device pixels Images can start to look pixellated 60. Tuesday, 31 July 2012
  • 61. Solutions <img src="500px_image.jpg" width="250"> 61. Tuesday, 31 July 2012
  • 62. Solutions @media screen and (-o-min-device-pixel- ratio: 3/2) { body { background-size: 250px; } } @media screen and (-webkit-min-device- pixel-ratio: 1.5) { body { background-size: 250px; } } 62. Tuesday, 31 July 2012
  • 64. Soon to be replaced by @media screen and (resolution: 1.5dppx) { body { background-size: 250px; } } 64. Tuesday, 31 July 2012
  • 65. Tell the truth with viewport <meta name="viewport" content="width=device-width, target-densitydpi=device-dpi"> 65. Tuesday, 31 July 2012
  • 66. All good, but... Images may now start to look a little small You could serve larger images for devices with higher resolutions 66. Tuesday, 31 July 2012
  • 67. Control mechanisms Currently tricky Usual wisdom about web sites applies: Make pages keyboard accessible, etc. Can’t be detected in CSS (yet) JavaScript touch detection is an option: Modernizr, jQuery 67. Tuesday, 31 July 2012
  • 68. “Subtle” advertisment Buy my book 68. Tuesday, 31 July 2012
  • 69. dev.opera.com | cmills@opera.com | @chrisdavidmills Thanks! 69. Tuesday, 31 July 2012