SlideShare a Scribd company logo
MEDIA QUERIES
 Mobile Elixir or CSS Snake Oil?
      james williamson | lynda.com
Howdy y’all
  james williamson

                   | senior author


     man-about-town

   @jameswillweb on the Twitter
Let’s Take Your Temperature...
Global mobile internet usage | 2003
Global mobile internet usage | 2011
Why do designers fear the mobile web?




        Because we’ve only just now
            gotten this to work
...and now we have to deal with this




             (images not to scale)
Past options for developing for the mobile web

          Build a separate mobile site.


          Hire a developer to build an app for you.



          Pray.
Surely there must be another option


                      CSS
               MEDIA
               QUERIES
               R
                Reflows content automatically, with no
               cramping or bloating. Works overnight, a
                  soothing balm for your mobile ills




        Good for what ails you?
So, what’s a media query?

CSS Media Queries give us a way to
 control the application of styles
based on the presence or absence
    of specific media features
The concept isn’t exactly new...


link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā media="screen"


                                                    look familiar?
However, we can now apply a little logic...


      link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
      media="screen	
 Ā and	
 Ā (min-­‐width:500px)"


                                       that narrows it down a bit.
Media Query syntax
  Media Queries are logical expressions, they are either
ā€œtrueā€ or ā€œfalseā€ depending upon how they are evaluated. If
   true, the styles are applied, if false, they are ignored.




       link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
       media="screen	
 Ā and	
 Ā (min-­‐width:500px)"


  In this example, the styles would only be applied if the UA supported the
           screen media type, and the display was at least 500px
Media Query syntax

    link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
media="[not	
 Ā |	
 Ā only	
 Ā ]	
 Ā screen	
 Ā [and]	
 Ā (expression)"




            The keywords ā€œnotā€, ā€œonlyā€, and ā€œandā€ can be
           used to filter results, while expressions can be
             used to check for specific media features
Media Query syntax
  Logical operator ā€œandā€ constrains a query based on the
expression that follows it. There is no ā€œorā€ operator, normal
               comma-separated lists serve as ā€œor.ā€


       link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
       media="screen	
 Ā and	
 Ā (min-­‐width:500px)"

 Styles are applied for screen devices that have a width of 500px or greater




   link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
   media="screen	
 Ā and	
 Ā (min-­‐width:500px),	
 Ā projection	
 Ā and	
 Ā (color)"



          Styles are applied for screen devices that have a width of
                 500px or greater, or color projection devices
Media Query syntax
Logical operator ā€œnotā€ negates the results of the media query
and applies the styles if the conditions are NOT met. It negates
   the entire expression, not just media type. Use carefully.




       link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
       media="not	
 Ā screen	
 Ā and	
 Ā (min-­‐width:500px)"



      Styles are applied if the device is not a screen device with a width
       above 499px. This also means that styles WOULD be applied for
       screen devices with widths below 500px and other media types.
Media Query syntax
Logical operator ā€œonlyā€ serves to hide style sheets from
older or non-conforming user agents. Conforming user
          agents are instructed to ignore ā€œonly.ā€




    link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā 
    media="only	
 Ā screen	
 Ā and	
 Ā (min-­‐width:500px)"



 Would be ignored by non-conforming agents. Other user agents would
    apply the styles to screen devices with widths 500px and above.
Media Query syntax

Media Features
width                     color
height                    color-­‐index
device-­‐width            monochrome
device-­‐height           resolution
orientation               scan
aspect-­‐ratio            grid
device-­‐aspect-­‐ratio
Media Query syntax

Media Feature values

length     width:500px


keyword    orientation:	
 Ā landscape	
 Ā |	
 Ā portrait

ratio      aspect-­‐ratio:	
 Ā 16/9

integer    color:8
Media Query syntax

Media Feature prefixes

In many cases, you can use the ā€œmin-ā€ and ā€œmax-ā€
prefixes to set less-than or greater-than ranges
for your values


                   width
                   min-­‐width
                   max-­‐width
Media Query syntax

Be careful!

         width	
 Ā !=	
 Ā device-­‐width


   (Honestly, even device-width != device width, or as
           PPK said, ā€œa pixel is not a pixel*ā€)




           *http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html
Enough syntax!
Let’s see it in action!




   Visit mediaqueri.es for a gallery of sites using media queries
Oh snap! That changes everything!

Except that it doesn’t.

We still need to talk about how media queries
work in the real world.
ā€œMedia queries are fools gold...ā€
                                           - Jason Grigsby*

So what’s his beef?


    Support for media queries isn’t that good




           *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
ā€œMedia queries are fools gold...ā€
                                           - Jason Grigsby*

So what’s his beef?


   Having browsers scale images is a bad idea




           *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
ā€œMedia queries are fools gold...ā€
                                          - Jason Grigsby*

So what’s his beef?


      Unnecessary resource downloading




          *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
ā€œMedia queries are fools gold...ā€
                                          - Jason Grigsby*

So what’s his beef?


    Hiding elements doesn’t lower overhead




          *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
ā€œMedia queries are fools gold...ā€
                                          - Jason Grigsby*

So what’s his beef?


    Media queries ignore the mobile context




          *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
Browser Support
Browser                     Layout Engine           MQ support
Firefox                     Gecko                      3.6+
Google	
 Ā Chrome            WebKit                     10+
Safari                      WebKit                     3.2+
Opera                       Presto                     11+
Internet	
 Ā Explorer        Trident                    9+
iOS	
 Ā Safari               WebKit                     3.2
Opera	
 Ā Mini               Presto                     5.0
Opera	
 Ā Mobile             Presto                     10.0
Android	
 Ā Browser	
 Ā       Android	
 Ā WebKit	
 Ā       2.1
Nokia                       multiple                   s40
Blackberry	
 Ā Browser       Mango/WebKit               4.7.1
Samsung                     Android	
 Ā WebKit          ???
OpenWave                    ???
UC	
 Ā Web                   proprietary
NetFront                    NetFront
Palm                        WebKit                     WebOS	
 Ā 1.4
Another big problem...it doesn’t just...work
  For mobile, media queries are typically used to check for screen
      size. They do not perform browser or device sniffing. The
   multitude of different screen sizes, resolutions, pixel densities,
    and default scaling preferences can cause serious problems
             with how media query-driven sites display.
Oh...so....I guess we can go now right?
                                     dang.




Not so fast. Media queries CAN work, and can be an important
part of your mobile development strategy... you just have to use
   them correctly, and combine them with other techniques
Let’s talk strategy




                Mobile First*
Popularized by Luke Wroblewski, it emphasizes
starting the design process with mobile in mind.



                            *http://www.lukew.com/presos/preso.asp?26
Mobile first media queries
In terms of media queries, mobile first means starting
with your mobile styles, and then enhancing designs
      for other screen sizes including desktop.
Now, about media query support...
             Respond.js from the Filament Group
                  https://github.com/scottjehl/Respond
                  (gzipped version is 1kb)



             css3-mediaqueries-js by Wouter van der Graaf
                  http://code.google.com/p/css3-mediaqueries-js/
                  (15kb uncompressed)



A mobile-first strategy makes using these libraries critical.
Now, let’s tame the viewport!


            CSS
     MEDIA
     QUERIES
                                                +   VIEWPORT
     R
      Reflows content automatically, with no
     cramping or bloating. Works overnight, a
        soothing balm for your mobile ills
                                                    Controls scaling and resolution with no
                                                      bloating, dizzyness, or unpleasant
                                                      aftertaste. A true joy for the home.




   = feel better by morning!
Meta Viewport tags

Meta viewport tags can be combined with media
queries to help ensure consistent experiences.



  <meta	
 Ā name="viewport"	
 Ā content="width=device-­‐width,	
 Ā 
  initial-­‐scale=1.0">


                                   what’s this all about then?
So what can meta viewport tags do?

    Meta Viewport properties

     width	
 Ā =	
 Ā [pixel	
 Ā |	
 Ā device-­‐width	
 Ā ]
     height	
 Ā =	
 Ā [pixel	
 Ā |	
 Ā device-­‐height	
 Ā ]



You can set width and height to explicit pixel values, or set
them to device width and height, which instruct the device
   to set the viewport width to the device screen width
So what can meta viewport tags do?

   Meta Viewport properties

    initial-­‐scale	
 Ā =	
 Ā 0*	
 Ā -­‐	
 Ā 10
    minimum-­‐scale	
 Ā =	
 Ā 0*	
 Ā -­‐	
 Ā 10
    maximum-­‐scale	
 Ā =	
 Ā 0*	
 Ā -­‐	
 Ā 10


These values allow you to control the initial scaling of the
page (to control whether your page is initially zoomed out
or not), and the minimum and maximum scaling allowed.


                                              * Android minimum is 0.01
So what can meta viewport tags do?

   Meta Viewport properties

    user-­‐scalable	
 Ā =	
 Ā [	
 Ā yes	
 Ā |	
 Ā no	
 Ā ]



Controls whether or not the user can change the scale of
  the page. If the value is set to no, any previously set
  minimum and maximum scaling values are ignored.
So what can meta viewport tags do?

     Meta Viewport properties

       target-­‐densitydpi	
 Ā =	
 Ā [	
 Ā dpi_value	
 Ā |	
 Ā device-­‐dpi	
 Ā 
       |	
 Ā high-­‐dpi	
 Ā |	
 Ā medium-­‐dpi	
 Ā |	
 Ā low-­‐dpi	
 Ā ]	
 Ā ]



Android Only: Allows you to target screen resolution. You can target a dpi
value (70 - 400), the device dpi (prevents default scaling), or you can target
one of three Android screen density categories. Content will then scale up
 or down if the resolution doesn’t match the target density. Essentially, it
     allows you to control how CSS pixels are scaled to device pixels.


     *For WebKit, you can use (-webkit-min-device-pixel-ratio: 2) to target higher density displays
Let’s look at that again...

    <meta	
 Ā name="viewport"	
 Ā content="width=device-­‐width,	
 Ā 
    initial-­‐scale=1.0">



This syntax tells the device to set the viewport width to the
actual device width to ensure the proper media query styles
      are used, and set the initial page scale to 100%.


  Never use media queries without a meta viewport tag.
                              Ever.
What about resource loading?

             OMG. I cannot believe
               I just ate all that!
The truth about media query loading...
      <link	
 Ā rel="stylesheet"	
 Ā href="desktop.css"	
 Ā media="screen,	
 Ā 
      projection">


      <link	
 Ā rel="stylesheet"	
 Ā href="tablet.css"	
 Ā media="all	
 Ā and	
 Ā 
      (min-­‐width:	
 Ā 481px)	
 Ā and	
 Ā (max-­‐width:	
 Ā 768px)">


      <link	
 Ā rel="stylesheet"	
 Ā href="mobile.css"	
 Ā media="all	
 Ā and	
 Ā 
      (min-­‐width:	
 Ā 0px)	
 Ā and	
 Ā (max-­‐width:	
 Ā 480px)">




   This is very inefficient. All three CSS files will load,
regardless of which media styles are loaded. This creates
    additional HTTP requests with no added savings.
    Combine these files using inline @media syntax.
The truth about media query loading...
      #actionCall	
 Ā {
      	
 Ā  display:	
 Ā none;
      }




  This doesn’t help you either. If a widget or image is
present in the element, it is still downloaded, regardless
                   of the display property.
The truth about media query loading...
     @media	
 Ā //mobile	
 Ā {
     #actionCall	
 Ā {
     	
 Ā  background:	
 Ā none;
     	
 Ā 	
 Ā }
     }
     @media	
 Ā //desktop	
 Ā {
     #actionCall	
 Ā {
     	
 Ā  background:	
 Ā url(big_ole_image.jpg);
     	
 Ā 	
 Ā }
     }


   This is better. If the mobile property is set to no
background image, iOS does not download the desktop
 version. Sadly it seems that Android currently does.
How can we control resource loading?


     Modernizr 2 features both media query tests AND the
YepNope.js library. This allows you to combine feature detection,
    media query success, and conditional resource loading.



                          <BOOM>
                    http://www.modernizr.com/
How can we control resource loading?
Of course, if you prefer, you can roll your own. PPK reports in his
   own testing, document.documentElement.clientWidth and
  screen.width give the same results as the width and device-
      width media queries*. This means you could do this:


        if	
 Ā (screen.width	
 Ā >=	
 Ā 600)	
 Ā {
        	
 Ā  //	
 Ā load	
 Ā resources
        }

        or
        if	
 Ā (document.documentElement.clientWidth	
 Ā >=	
 Ā 
        600)	
 Ā {
        	
 Ā  //	
 Ā load	
 Ā resources
        }



                  *http://www.quirksmode.org/blog/archives/2010/08/combining_media.html
Media Query best practices
Design with mobile in mind first

Make the mobile styles your default styles and progress up

Use fluid layouts to deal with minor screen size differences

Combine CSS & JS files to reduce HTTP requests

Minimize and gzip compress your code

Use Data URL and CSS Sprites when you can

Don’t use external libraries unless you really need to

Consider using touch frameworks for interactivity
Looks like gold to me!



                       CSS
                MEDIA
                QUERIES
                R
                 Reflows content automatically, with no
                cramping or bloating. Works overnight, a
                   soothing balm for your mobile ills




(That? Oh, that’s just the halo of truth...)
So...where does that leave us?
Just like every other technique in your toolbox, media
queries simply add to your capabilities.


Are they right for every project? Of course not. Mobile
design is far more than simply designing for a smaller
screen.


However, given the right circumstances, media queries
allow you to optimize designs for the mobile environment
in a way that we weren’t able to do before.


Deciding when, and if, to use them is, after all, your job.
THANK YOU
james williamson | lynda.com
   jwilliamson@lynda.com
@jameswillweb on the Twitter
  www.simpleprimate.com

More Related Content

What's hot (18)

Class 4: Introduction to web technology entrepreneurship
Class 4: Introduction to web technology entrepreneurshipClass 4: Introduction to web technology entrepreneurship
Class 4: Introduction to web technology entrepreneurship
allanchao
Ā 
Creating mobile apps without native code
Creating mobile apps without native codeCreating mobile apps without native code
Creating mobile apps without native code
Joakim Kemeny
Ā 
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Nathaniel Bagnell
Ā 
The future of media queries?
The future of media queries?The future of media queries?
The future of media queries?
yiibu
Ā 
Mobile UI Design Patterns
Mobile UI Design PatternsMobile UI Design Patterns
Mobile UI Design Patterns
danhermes
Ā 
Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!
Courtney Jordan
Ā 
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
Ā 
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical web
yiibu
Ā 
Cm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learnCm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learn
Critical Mass
Ā 
Product Based Virtual Worlds For College Recruiting
Product Based Virtual Worlds For College RecruitingProduct Based Virtual Worlds For College Recruiting
Product Based Virtual Worlds For College Recruiting
Andrew Hughes
Ā 
Web Design Trends For 2016
Web Design Trends For 2016Web Design Trends For 2016
Web Design Trends For 2016
PixelCrayons
Ā 
Google Developer Day: State of Ajax
Google Developer Day: State of AjaxGoogle Developer Day: State of Ajax
Google Developer Day: State of Ajax
dion
Ā 
Explaining Ajax
Explaining AjaxExplaining Ajax
Explaining Ajax
Web Directions
Ā 
Your Mobile Strategy Can't Be HTML5
Your Mobile Strategy Can't Be HTML5Your Mobile Strategy Can't Be HTML5
Your Mobile Strategy Can't Be HTML5
Theresa Neil
Ā 
Accessible Responsive Web Design
Accessible Responsive Web DesignAccessible Responsive Web Design
Accessible Responsive Web Design
Interactive Accessibility
Ā 
Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]
Aaron Gustafson
Ā 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices
mintersam
Ā 
Web design and development trends
Web design and development  trendsWeb design and development  trends
Web design and development trends
Cool Sky
Ā 
Class 4: Introduction to web technology entrepreneurship
Class 4: Introduction to web technology entrepreneurshipClass 4: Introduction to web technology entrepreneurship
Class 4: Introduction to web technology entrepreneurship
allanchao
Ā 
Creating mobile apps without native code
Creating mobile apps without native codeCreating mobile apps without native code
Creating mobile apps without native code
Joakim Kemeny
Ā 
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 – Application Development with HTML 5
Nathaniel Bagnell
Ā 
The future of media queries?
The future of media queries?The future of media queries?
The future of media queries?
yiibu
Ā 
Mobile UI Design Patterns
Mobile UI Design PatternsMobile UI Design Patterns
Mobile UI Design Patterns
danhermes
Ā 
Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!
Courtney Jordan
Ā 
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
Ā 
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical web
yiibu
Ā 
Cm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learnCm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learn
Critical Mass
Ā 
Product Based Virtual Worlds For College Recruiting
Product Based Virtual Worlds For College RecruitingProduct Based Virtual Worlds For College Recruiting
Product Based Virtual Worlds For College Recruiting
Andrew Hughes
Ā 
Web Design Trends For 2016
Web Design Trends For 2016Web Design Trends For 2016
Web Design Trends For 2016
PixelCrayons
Ā 
Google Developer Day: State of Ajax
Google Developer Day: State of AjaxGoogle Developer Day: State of Ajax
Google Developer Day: State of Ajax
dion
Ā 
Your Mobile Strategy Can't Be HTML5
Your Mobile Strategy Can't Be HTML5Your Mobile Strategy Can't Be HTML5
Your Mobile Strategy Can't Be HTML5
Theresa Neil
Ā 
Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]
Aaron Gustafson
Ā 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices
mintersam
Ā 
Web design and development trends
Web design and development  trendsWeb design and development  trends
Web design and development trends
Cool Sky
Ā 

Viewers also liked (6)

Designing for a Better User Experience
Designing for a Better User ExperienceDesigning for a Better User Experience
Designing for a Better User Experience
BuiltByHQ
Ā 
Typography in Web Design (WordCamp Toronto 2014)
Typography in Web Design (WordCamp Toronto 2014)Typography in Web Design (WordCamp Toronto 2014)
Typography in Web Design (WordCamp Toronto 2014)
Jasmine Vesque
Ā 
Wireframes for WordPress
Wireframes for WordPressWireframes for WordPress
Wireframes for WordPress
John Housholder
Ā 
The Ultimate Guide to Font Pairing
The Ultimate Guide to Font PairingThe Ultimate Guide to Font Pairing
The Ultimate Guide to Font Pairing
Guy Kawasaki
Ā 
Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3
M. Jackson Wilkinson
Ā 
An introduction to Usability
An introduction to UsabilityAn introduction to Usability
An introduction to Usability
Erlend Debast
Ā 
Designing for a Better User Experience
Designing for a Better User ExperienceDesigning for a Better User Experience
Designing for a Better User Experience
BuiltByHQ
Ā 
Typography in Web Design (WordCamp Toronto 2014)
Typography in Web Design (WordCamp Toronto 2014)Typography in Web Design (WordCamp Toronto 2014)
Typography in Web Design (WordCamp Toronto 2014)
Jasmine Vesque
Ā 
Wireframes for WordPress
Wireframes for WordPressWireframes for WordPress
Wireframes for WordPress
John Housholder
Ā 
The Ultimate Guide to Font Pairing
The Ultimate Guide to Font PairingThe Ultimate Guide to Font Pairing
The Ultimate Guide to Font Pairing
Guy Kawasaki
Ā 
Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3
M. Jackson Wilkinson
Ā 
An introduction to Usability
An introduction to UsabilityAn introduction to Usability
An introduction to Usability
Erlend Debast
Ā 
Ad

Similar to CSS3 Media Queries: Mobile Elixir or CSS Snake Oil (20)

Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Patrick Lauke
Ā 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
Mike Wilcox
Ā 
The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktop
betabeers
Ā 
Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123
Hina Chen
Ā 
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
arborwebsolutions
Ā 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
Joe Seifi
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Julia Vi
Ā 
Responsive web design
Responsive web designResponsive web design
Responsive web design
Adheetha O. V
Ā 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
Russ Weakley
Ā 
Beyond Responsive Web Design
Beyond Responsive Web DesignBeyond Responsive Web Design
Beyond Responsive Web Design
arborwebsolutions
Ā 
Building Responsive Websites and Apps with Drupal
Building Responsive Websites and Apps with DrupalBuilding Responsive Websites and Apps with Drupal
Building Responsive Websites and Apps with Drupal
Four Kitchens
Ā 
CSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experienceCSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experience
Zoe Gillenwater
Ā 
Responsive Web Site Design
Responsive Web Site DesignResponsive Web Site Design
Responsive Web Site Design
Jussi Pohjolainen
Ā 
Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011
Patrick Lauke
Ā 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
Ā 
Optimizing content for the "mobile web"
Optimizing content for the "mobile web"Optimizing content for the "mobile web"
Optimizing content for the "mobile web"
Chris Mills
Ā 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queries
Stephen Hay
Ā 
Media Query
Media QueryMedia Query
Media Query
ipower softwares
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Jason Harwig
Ā 
Responsive Web Design - Breaking Points
Responsive Web Design - Breaking PointsResponsive Web Design - Breaking Points
Responsive Web Design - Breaking Points
Susan Price
Ā 
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Patrick Lauke
Ā 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
Mike Wilcox
Ā 
The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktop
betabeers
Ā 
Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123
Hina Chen
Ā 
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
(Practical) Beyond Responsive Web Design (WordCamp Miami 2011)
arborwebsolutions
Ā 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
Joe Seifi
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Julia Vi
Ā 
Responsive web design
Responsive web designResponsive web design
Responsive web design
Adheetha O. V
Ā 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
Russ Weakley
Ā 
Beyond Responsive Web Design
Beyond Responsive Web DesignBeyond Responsive Web Design
Beyond Responsive Web Design
arborwebsolutions
Ā 
Building Responsive Websites and Apps with Drupal
Building Responsive Websites and Apps with DrupalBuilding Responsive Websites and Apps with Drupal
Building Responsive Websites and Apps with Drupal
Four Kitchens
Ā 
CSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experienceCSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experience
Zoe Gillenwater
Ā 
Responsive Web Site Design
Responsive Web Site DesignResponsive Web Site Design
Responsive Web Site Design
Jussi Pohjolainen
Ā 
Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011
Patrick Lauke
Ā 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
Ā 
Optimizing content for the "mobile web"
Optimizing content for the "mobile web"Optimizing content for the "mobile web"
Optimizing content for the "mobile web"
Chris Mills
Ā 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queries
Stephen Hay
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Jason Harwig
Ā 
Responsive Web Design - Breaking Points
Responsive Web Design - Breaking PointsResponsive Web Design - Breaking Points
Responsive Web Design - Breaking Points
Susan Price
Ā 
Ad

More from jameswillweb (7)

Hooray Icon Fonts!
Hooray Icon Fonts!Hooray Icon Fonts!
Hooray Icon Fonts!
jameswillweb
Ā 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconf
jameswillweb
Ā 
Developing Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CCDeveloping Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CC
jameswillweb
Ā 
Designing Responsively with Dreamweaver
Designing Responsively with DreamweaverDesigning Responsively with Dreamweaver
Designing Responsively with Dreamweaver
jameswillweb
Ā 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
jameswillweb
Ā 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
jameswillweb
Ā 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
jameswillweb
Ā 
Hooray Icon Fonts!
Hooray Icon Fonts!Hooray Icon Fonts!
Hooray Icon Fonts!
jameswillweb
Ā 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconf
jameswillweb
Ā 
Developing Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CCDeveloping Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CC
jameswillweb
Ā 
Designing Responsively with Dreamweaver
Designing Responsively with DreamweaverDesigning Responsively with Dreamweaver
Designing Responsively with Dreamweaver
jameswillweb
Ā 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
jameswillweb
Ā 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
jameswillweb
Ā 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
jameswillweb
Ā 

Recently uploaded (20)

Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
Ā 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
Ā 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
Ā 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
Ā 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
Ā 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
Ā 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
Ā 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
Ā 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
Ā 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
Ā 
AI Emotional Actors: ā€œWhen Machines Learn to Feel and Perform"
AI Emotional Actors:  ā€œWhen Machines Learn to Feel and Perform"AI Emotional Actors:  ā€œWhen Machines Learn to Feel and Perform"
AI Emotional Actors: ā€œWhen Machines Learn to Feel and Perform"
AkashKumar809858
Ā 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
Ā 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
Ā 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
Ā 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
Ā 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
Ā 
Let’s Get Slack Certified! šŸš€- Slack Community
Let’s Get Slack Certified! šŸš€- Slack CommunityLet’s Get Slack Certified! šŸš€- Slack Community
Let’s Get Slack Certified! šŸš€- Slack Community
SanjeetMishra29
Ā 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
Ā 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
Ā 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
Ā 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
Ā 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
Ā 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
Ā 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
Ā 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
Ā 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
Ā 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
Ā 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
Ā 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
Ā 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
Ā 
AI Emotional Actors: ā€œWhen Machines Learn to Feel and Perform"
AI Emotional Actors:  ā€œWhen Machines Learn to Feel and Perform"AI Emotional Actors:  ā€œWhen Machines Learn to Feel and Perform"
AI Emotional Actors: ā€œWhen Machines Learn to Feel and Perform"
AkashKumar809858
Ā 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
Ā 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
Ā 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
Ā 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
Ā 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
Ā 
Let’s Get Slack Certified! šŸš€- Slack Community
Let’s Get Slack Certified! šŸš€- Slack CommunityLet’s Get Slack Certified! šŸš€- Slack Community
Let’s Get Slack Certified! šŸš€- Slack Community
SanjeetMishra29
Ā 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
Ā 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
Ā 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
Ā 

CSS3 Media Queries: Mobile Elixir or CSS Snake Oil

  • 1. MEDIA QUERIES Mobile Elixir or CSS Snake Oil? james williamson | lynda.com
  • 2. Howdy y’all james williamson | senior author man-about-town @jameswillweb on the Twitter
  • 3. Let’s Take Your Temperature...
  • 4. Global mobile internet usage | 2003
  • 5. Global mobile internet usage | 2011
  • 6. Why do designers fear the mobile web? Because we’ve only just now gotten this to work
  • 7. ...and now we have to deal with this (images not to scale)
  • 8. Past options for developing for the mobile web Build a separate mobile site. Hire a developer to build an app for you. Pray.
  • 9. Surely there must be another option CSS MEDIA QUERIES R Reflows content automatically, with no cramping or bloating. Works overnight, a soothing balm for your mobile ills Good for what ails you?
  • 10. So, what’s a media query? CSS Media Queries give us a way to control the application of styles based on the presence or absence of specific media features
  • 11. The concept isn’t exactly new... link Ā rel="stylesheet" Ā href="desktop.css" Ā media="screen" look familiar?
  • 12. However, we can now apply a little logic... link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="screen Ā and Ā (min-­‐width:500px)" that narrows it down a bit.
  • 13. Media Query syntax Media Queries are logical expressions, they are either ā€œtrueā€ or ā€œfalseā€ depending upon how they are evaluated. If true, the styles are applied, if false, they are ignored. link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="screen Ā and Ā (min-­‐width:500px)" In this example, the styles would only be applied if the UA supported the screen media type, and the display was at least 500px
  • 14. Media Query syntax link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="[not Ā | Ā only Ā ] Ā screen Ā [and] Ā (expression)" The keywords ā€œnotā€, ā€œonlyā€, and ā€œandā€ can be used to filter results, while expressions can be used to check for specific media features
  • 15. Media Query syntax Logical operator ā€œandā€ constrains a query based on the expression that follows it. There is no ā€œorā€ operator, normal comma-separated lists serve as ā€œor.ā€ link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="screen Ā and Ā (min-­‐width:500px)" Styles are applied for screen devices that have a width of 500px or greater link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="screen Ā and Ā (min-­‐width:500px), Ā projection Ā and Ā (color)" Styles are applied for screen devices that have a width of 500px or greater, or color projection devices
  • 16. Media Query syntax Logical operator ā€œnotā€ negates the results of the media query and applies the styles if the conditions are NOT met. It negates the entire expression, not just media type. Use carefully. link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="not Ā screen Ā and Ā (min-­‐width:500px)" Styles are applied if the device is not a screen device with a width above 499px. This also means that styles WOULD be applied for screen devices with widths below 500px and other media types.
  • 17. Media Query syntax Logical operator ā€œonlyā€ serves to hide style sheets from older or non-conforming user agents. Conforming user agents are instructed to ignore ā€œonly.ā€ link Ā rel="stylesheet" Ā href="desktop.css" Ā  media="only Ā screen Ā and Ā (min-­‐width:500px)" Would be ignored by non-conforming agents. Other user agents would apply the styles to screen devices with widths 500px and above.
  • 18. Media Query syntax Media Features width color height color-­‐index device-­‐width monochrome device-­‐height resolution orientation scan aspect-­‐ratio grid device-­‐aspect-­‐ratio
  • 19. Media Query syntax Media Feature values length width:500px keyword orientation: Ā landscape Ā | Ā portrait ratio aspect-­‐ratio: Ā 16/9 integer color:8
  • 20. Media Query syntax Media Feature prefixes In many cases, you can use the ā€œmin-ā€ and ā€œmax-ā€ prefixes to set less-than or greater-than ranges for your values width min-­‐width max-­‐width
  • 21. Media Query syntax Be careful! width Ā != Ā device-­‐width (Honestly, even device-width != device width, or as PPK said, ā€œa pixel is not a pixel*ā€) *http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html
  • 22. Enough syntax! Let’s see it in action! Visit mediaqueri.es for a gallery of sites using media queries
  • 23. Oh snap! That changes everything! Except that it doesn’t. We still need to talk about how media queries work in the real world.
  • 24. ā€œMedia queries are fools gold...ā€ - Jason Grigsby* So what’s his beef? Support for media queries isn’t that good *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
  • 25. ā€œMedia queries are fools gold...ā€ - Jason Grigsby* So what’s his beef? Having browsers scale images is a bad idea *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
  • 26. ā€œMedia queries are fools gold...ā€ - Jason Grigsby* So what’s his beef? Unnecessary resource downloading *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
  • 27. ā€œMedia queries are fools gold...ā€ - Jason Grigsby* So what’s his beef? Hiding elements doesn’t lower overhead *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
  • 28. ā€œMedia queries are fools gold...ā€ - Jason Grigsby* So what’s his beef? Media queries ignore the mobile context *http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/
  • 29. Browser Support Browser Layout Engine MQ support Firefox Gecko 3.6+ Google Ā Chrome WebKit 10+ Safari WebKit 3.2+ Opera Presto 11+ Internet Ā Explorer Trident 9+ iOS Ā Safari WebKit 3.2 Opera Ā Mini Presto 5.0 Opera Ā Mobile Presto 10.0 Android Ā Browser Ā  Android Ā WebKit Ā  2.1 Nokia multiple s40 Blackberry Ā Browser Mango/WebKit 4.7.1 Samsung Android Ā WebKit ??? OpenWave ??? UC Ā Web proprietary NetFront NetFront Palm WebKit WebOS Ā 1.4
  • 30. Another big problem...it doesn’t just...work For mobile, media queries are typically used to check for screen size. They do not perform browser or device sniffing. The multitude of different screen sizes, resolutions, pixel densities, and default scaling preferences can cause serious problems with how media query-driven sites display.
  • 31. Oh...so....I guess we can go now right? dang. Not so fast. Media queries CAN work, and can be an important part of your mobile development strategy... you just have to use them correctly, and combine them with other techniques
  • 32. Let’s talk strategy Mobile First* Popularized by Luke Wroblewski, it emphasizes starting the design process with mobile in mind. *http://www.lukew.com/presos/preso.asp?26
  • 33. Mobile first media queries In terms of media queries, mobile first means starting with your mobile styles, and then enhancing designs for other screen sizes including desktop.
  • 34. Now, about media query support... Respond.js from the Filament Group https://github.com/scottjehl/Respond (gzipped version is 1kb) css3-mediaqueries-js by Wouter van der Graaf http://code.google.com/p/css3-mediaqueries-js/ (15kb uncompressed) A mobile-first strategy makes using these libraries critical.
  • 35. Now, let’s tame the viewport! CSS MEDIA QUERIES + VIEWPORT R Reflows content automatically, with no cramping or bloating. Works overnight, a soothing balm for your mobile ills Controls scaling and resolution with no bloating, dizzyness, or unpleasant aftertaste. A true joy for the home. = feel better by morning!
  • 36. Meta Viewport tags Meta viewport tags can be combined with media queries to help ensure consistent experiences. <meta Ā name="viewport" Ā content="width=device-­‐width, Ā  initial-­‐scale=1.0"> what’s this all about then?
  • 37. So what can meta viewport tags do? Meta Viewport properties width Ā = Ā [pixel Ā | Ā device-­‐width Ā ] height Ā = Ā [pixel Ā | Ā device-­‐height Ā ] You can set width and height to explicit pixel values, or set them to device width and height, which instruct the device to set the viewport width to the device screen width
  • 38. So what can meta viewport tags do? Meta Viewport properties initial-­‐scale Ā = Ā 0* Ā -­‐ Ā 10 minimum-­‐scale Ā = Ā 0* Ā -­‐ Ā 10 maximum-­‐scale Ā = Ā 0* Ā -­‐ Ā 10 These values allow you to control the initial scaling of the page (to control whether your page is initially zoomed out or not), and the minimum and maximum scaling allowed. * Android minimum is 0.01
  • 39. So what can meta viewport tags do? Meta Viewport properties user-­‐scalable Ā = Ā [ Ā yes Ā | Ā no Ā ] Controls whether or not the user can change the scale of the page. If the value is set to no, any previously set minimum and maximum scaling values are ignored.
  • 40. So what can meta viewport tags do? Meta Viewport properties target-­‐densitydpi Ā = Ā [ Ā dpi_value Ā | Ā device-­‐dpi Ā  | Ā high-­‐dpi Ā | Ā medium-­‐dpi Ā | Ā low-­‐dpi Ā ] Ā ] Android Only: Allows you to target screen resolution. You can target a dpi value (70 - 400), the device dpi (prevents default scaling), or you can target one of three Android screen density categories. Content will then scale up or down if the resolution doesn’t match the target density. Essentially, it allows you to control how CSS pixels are scaled to device pixels. *For WebKit, you can use (-webkit-min-device-pixel-ratio: 2) to target higher density displays
  • 41. Let’s look at that again... <meta Ā name="viewport" Ā content="width=device-­‐width, Ā  initial-­‐scale=1.0"> This syntax tells the device to set the viewport width to the actual device width to ensure the proper media query styles are used, and set the initial page scale to 100%. Never use media queries without a meta viewport tag. Ever.
  • 42. What about resource loading? OMG. I cannot believe I just ate all that!
  • 43. The truth about media query loading... <link Ā rel="stylesheet" Ā href="desktop.css" Ā media="screen, Ā  projection"> <link Ā rel="stylesheet" Ā href="tablet.css" Ā media="all Ā and Ā  (min-­‐width: Ā 481px) Ā and Ā (max-­‐width: Ā 768px)"> <link Ā rel="stylesheet" Ā href="mobile.css" Ā media="all Ā and Ā  (min-­‐width: Ā 0px) Ā and Ā (max-­‐width: Ā 480px)"> This is very inefficient. All three CSS files will load, regardless of which media styles are loaded. This creates additional HTTP requests with no added savings. Combine these files using inline @media syntax.
  • 44. The truth about media query loading... #actionCall Ā { Ā  display: Ā none; } This doesn’t help you either. If a widget or image is present in the element, it is still downloaded, regardless of the display property.
  • 45. The truth about media query loading... @media Ā //mobile Ā { #actionCall Ā { Ā  background: Ā none; Ā  Ā } } @media Ā //desktop Ā { #actionCall Ā { Ā  background: Ā url(big_ole_image.jpg); Ā  Ā } } This is better. If the mobile property is set to no background image, iOS does not download the desktop version. Sadly it seems that Android currently does.
  • 46. How can we control resource loading? Modernizr 2 features both media query tests AND the YepNope.js library. This allows you to combine feature detection, media query success, and conditional resource loading. <BOOM> http://www.modernizr.com/
  • 47. How can we control resource loading? Of course, if you prefer, you can roll your own. PPK reports in his own testing, document.documentElement.clientWidth and screen.width give the same results as the width and device- width media queries*. This means you could do this: if Ā (screen.width Ā >= Ā 600) Ā { Ā  // Ā load Ā resources } or if Ā (document.documentElement.clientWidth Ā >= Ā  600) Ā { Ā  // Ā load Ā resources } *http://www.quirksmode.org/blog/archives/2010/08/combining_media.html
  • 48. Media Query best practices Design with mobile in mind first Make the mobile styles your default styles and progress up Use fluid layouts to deal with minor screen size differences Combine CSS & JS files to reduce HTTP requests Minimize and gzip compress your code Use Data URL and CSS Sprites when you can Don’t use external libraries unless you really need to Consider using touch frameworks for interactivity
  • 49. Looks like gold to me! CSS MEDIA QUERIES R Reflows content automatically, with no cramping or bloating. Works overnight, a soothing balm for your mobile ills (That? Oh, that’s just the halo of truth...)
  • 50. So...where does that leave us? Just like every other technique in your toolbox, media queries simply add to your capabilities. Are they right for every project? Of course not. Mobile design is far more than simply designing for a smaller screen. However, given the right circumstances, media queries allow you to optimize designs for the mobile environment in a way that we weren’t able to do before. Deciding when, and if, to use them is, after all, your job.
  • 51. THANK YOU james williamson | lynda.com jwilliamson@lynda.com @jameswillweb on the Twitter www.simpleprimate.com