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

Recommended for you

The future of media queries?
The future of media queries?The future of media queries?
The future of media queries?

A brief exploration of proposed Level 4 Media Queries and some thoughts about the future of the web. Presented at Responsive Day Out in Brighton on June 27 2014.

future of the webmobilew3c
Mobile UI Design Patterns
Mobile UI Design PatternsMobile UI Design Patterns
Mobile UI Design Patterns

This document discusses various mobile design patterns and concepts. It covers common UI patterns like lists, navigation, and forms. It also discusses design principles for mobile like direct manipulation and feedback. It provides examples of implementing lists in Android and iOS. It compares MVC and MVVM patterns and discusses using MVVM frameworks. It emphasizes adapting patterns from desktop to be optimized for mobile interaction paradigms.

Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!

Slide-deck covers what is responsive web design, why use it and a walk-through of The Department of Labor's Ride Safe New York website going responsive.

responsive designdesignweb design
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.

Recommended for you

Using Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetUsing Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component Set

This document is a presentation by Joseph Labrecque on using Edge Animate to create reusable component sets. The presentation covers Edge Animate and component creation, including an overview of Edge Animate, a discussion of historical component creation, anatomy of Edge Animate compositions, creating simple and advanced components, component libraries, and resources. Live demos are provided of creating components in both Flash Professional and Edge Animate.

edge animateadobe maxhtml5
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)

This document discusses mobile web development techniques and Opera's developer tools. It outlines three approaches to catering websites for mobile users: doing nothing, creating a separate mobile site, or creating one site that works for all devices. Key techniques discussed include using the viewport meta tag to control zoom levels, media queries to apply different CSS styles based on screen width, and keeping mobile design in mind from the start to simplify layouts. The document promotes the goal of a "one site holy grail" that works seamlessly across devices and concludes by introducing Opera's developer tools for testing mobile webpages.

media queriesm2eumobile
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical web

Today’s 'smart devices' are a product of the technology and mental models of our past. From a connected lightbulb to a robot vacuum, using most of these devices requires a native app. This in turn greatly limits their contexts of use. Can we really expect users to download an app to interact with a random ’thing’ they encounter at the mall, a space they explore for an hour at the museum, or a city they will only visit for a day? What devices could we build, what 'smart' environments could we enable if users could simply discover, “walk up and use”(and then if needed, abandon) these objects and environments as they do a web site? This workshop will discuss two new technologies--Physical Web and Web Bluetooth--that can enable on-demand interaction with physical things and spaces using no more than a browser.

bluetooth lemobile marketingbluetooth
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.

Recommended for you

Cm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learnCm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learn

This document provides an overview of developing apps for the iPad using web technologies like HTML5, CSS3, and JavaScript compared to developing native apps. It discusses key differences like the APIs available, performance, costs, updating processes, and more. It then provides best practices for web design on iPads, including considerations for touch targets, orientations, animations, images, and more. It also covers specific technologies like HTML5, CSS3, JavaScript, and backend development approaches. The overall message is that web development for iPads is very capable with modern techniques.

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

The document discusses virtual world options for educational institutions. It provides information on commercial virtual worlds like Second Life, open source options like OpenSim, and browser-based virtual worlds. It also introduces 3D Virtual Campus Tours, a product designed by Designing Digitally specifically for higher education recruitment. Key features highlighted are that it is fully browser-based, specialized for enrollment, and can replicate a campus in high quality graphics. Potential downfalls discussed are higher pricing and lack of editing tools compared to other virtual worlds.

virtual campuscollege recruitingvirtual campus tours
Web Design Trends For 2016
Web Design Trends For 2016Web Design Trends For 2016
Web Design Trends For 2016

With upcoming frameworks, powerful development tools and evolving technologies, this year looks very promising for web developers. Here are our thoughts on the top web development trends for 2016.

web trends 2016web developmentweb design trends
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.

Recommended for you

Google Developer Day: State of Ajax
Google Developer Day: State of AjaxGoogle Developer Day: State of Ajax
Google Developer Day: State of Ajax

At various Google Developer Day events in Europe I gave a talk on the State of Ajax, that focuses on the core issue of User Experience and where to go from here.

 
by dion
uxajaxgdd
Explaining Ajax
Explaining AjaxExplaining Ajax
Explaining Ajax

Apart from being the buzzword de jour, what is this Ajax stuff that everyone is talking about? Take a look at some implementations out there and start thinking about how Ajax can add value to your site.

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

Earlier this month, I presented an updated talk on Mobile Strategy for Servoy. This one hour talk looks at the 3 options for a mobile strategy: Responsive Web, Mobile Optimized, and/or Native. I also explained why HTML5 is not a strategy; it is merely a technology you can use to implement any and all of these options. And we briefly discussed the three faces of Mobile First and how this methodology helps companies break out of old habits to create better customer experiences.

mobile designmobile uxmobile sites
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

Recommended for you

Accessible Responsive Web Design
Accessible Responsive Web DesignAccessible Responsive Web Design
Accessible Responsive Web Design

Does responsive design make a website more or less accessible? In this session you will learn best practices and techniques for accessible responsive design. Responsive web design (RWD) can be very good for accessibility but is also poses some new challenges and design considerations to provide an optimal experience for people with disabilities. When done properly, RWD can address many accessibility issues related to low vision and certain mobility impairments. While responsive web design was not created specifically to address accessibility, its aim is to craft sites to provide an optimal viewing experience and easy navigation for all users and thereby address some accessibility issues. RWD enables the website to adapt its layout to the format of the viewing environment through the use of fluid, proportion-based grids, flexible images and CSS3 media queries. Responsive sites adjust to the screen and presents in the most readable and usable way for that particular screen size and format. This can ensure that font size remains readable and at a high resolution for people with low vision. It also keeps interactive elements large and easier to operate for people with mobility impairments. In this session we will review what a responsive website is and talk about the challenges and opportunities for accessibility in regards to responsive web design.

responsive web designwcagsection 508
Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]

Progressive Enhancement, the heart of Adaptive Design, makes the life of a design less complicated. Considerations like browser types, accessibility, device compatibility, and responsive or adaptive design are a lot to juggle. Start by creating a solid core and build out to craft amazing user experiences that work regardless of devices capabilities or deficiencies.

Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices

A brief presentation for the Missouri State Digital Media Developer group on cutting through the hype surrounding mobile development and responsive design.

responsive designmomedia query
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/

Recommended for you

Web design and development trends
Web design and development  trendsWeb design and development  trends
Web design and development trends

Web development is a broad term that includes various activities involved in developing websites and web applications. It involves web design, content development, scripting, security configuration, and e-commerce applications. Web design encompasses skills like graphic design, interface design, coding, search engine optimization and more. The history of web development began in 1989 with Tim Berners-Lee's proposal to create the World Wide Web. Many technologies were developed throughout the 90s and 2000s that shaped the modern web, including HTML, CSS, JavaScript, browsers, servers, smartphones and more.

web design and development trends
Designing for a Better User Experience
Designing for a Better User ExperienceDesigning for a Better User Experience
Designing for a Better User Experience

The document provides design tips for creating effective web and mobile designs. It recommends focusing on goals and audience, balancing form and function, using alignment and white space to create order and focus on content. It also suggests using typography, contrast, simplicity, and current trends while being subtle to create a delightful user experience.

ux designwebsite designdesign
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)

I delivered this presentation at WordCamp Toronto, November 15, 2014. This presentation covers typography basics and best practices, type trends in web design, personalities of type, an introduction to Google Fonts and different ways to enable fonts on your WordPress website. The ideal audience is anyone looking to better understand Typography and how it relates to web design. They don’t need to have a coding or design background, but that would be an asset. Learning Outcomes Understand the different types of fonts and when to use them Recognize the various personalities and tones fonts have and how they can affect your message Know what the current trends are in Typography and web design Use theme options and/or plugins to modify fonts Leverage Google Fonts and integrate them directly into your theme

typographyweb designwordpress
“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/

Recommended for you

Wireframes for WordPress
Wireframes for WordPressWireframes for WordPress
Wireframes for WordPress

Have you ever built a house? Imagine buying a lot, hiring a contractor, and then he shows up with a crane, bulldozer, and some 'crete and says "I'm ready." We often do the same thing when we build websites. We know we want a website, but don't do the necessary planning to turn our ideas into reality. In wireframes for WordPress, I will discuss what wireframes are, my process for creating them, and how they fit into WordPress.

wordcampwordcamp nashvillewireframes for wordpress
The Ultimate Guide to Font Pairing
The Ultimate Guide to Font PairingThe Ultimate Guide to Font Pairing
The Ultimate Guide to Font Pairing

Good graphic design doesn’t happen by mistake, and neither does clever font marriage. With this Ultimate Guide to Font Pairing we show you how to make your designs beautiful, with simple and effective type applications Read more at http://blog.canva.com/the-ultimate-guide-to-font-pairing/#Q3yEZPx6iwbBkRME.99

font choicesdesigngraphic design
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

A presentation to Refresh DC about the emerging HTML 5 and CSS 3 standards, namely about aspects that are beginning to become applicable to web design and development. Given by Jason Garber and M. Jackson Wilkinson.

mjacksonwilkinsonjacksonwilkinsonjasongarber
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

Recommended for you

An introduction to Usability
An introduction to UsabilityAn introduction to Usability
An introduction to Usability

The document discusses usability and provides tips for improving the usability of websites. It addresses common usability issues like not knowing what page you are on or not being able to find what you are looking for. It provides solutions like ensuring the logo links to the home page, using clear navigation, typography, forms, and calls to action. The document emphasizes that usability is important for user satisfaction and business results.

usabilityuxwebdesign
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design

The document discusses responsive web design and how it offers a way forward to design work meant for different experiences across a gradient of devices. It provides examples of using CSS media queries to serve different stylesheets based on screen width and other device features. This allows content to adapt to different screens from mobile to desktop in a fluid, responsive way.

lightning_talkcssweb design and development
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites

Introduction to Responsive Web Design http://tinyurl.com/9ldo4c6 Includes a sample project built from scratch in Node.js using LESS available on Github

web designresponsive web designmobile
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?

Recommended for you

Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)

Responsive Design is the buzz in design, but as we all know, design is only part of the story. With the arrival of the HTML5, CSS3 and javascript triumvirate we can no make truly immersive mobile and desktop browser experiences. Coupled with modern PHP web application practices, your web app will feel and act closer to a native app, at a fraction of the cost. In this presentation, we'll dive into designing your modern web application to take advantage of as much of the platforms' limitations and advantages. Sure, you can't use the camera, but in many cases can use the accelerometer, and it'll always be granted to look right, any angle you look at it! These days, there's no excuse for not having a "mobile version" when all you need is one site that can transform itself to suit the device!

responsive designweb design and development
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web Design

Responsive web design allows a website to adapt to different screen sizes using fluid grids, scalable images, and media queries. It involves developing sites using relative units like percentages instead of pixels so elements resize proportionately. Media queries allow different CSS stylesheets to be loaded depending on screen width, orientiation, resolution and other factors. This allows a single website to be accessed seamlessly on any device from phones to desktops to tablets without needing separate mobile sites.

advancioinc academyresponsive web design
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design

This document discusses responsive web design using CSS3 media queries. It begins with an introduction to media queries and their syntax for modifying CSS based on screen width. It then covers examples of adapting layouts, images, and other design elements for different screen sizes. Finally, it addresses techniques for supporting older browsers that do not support media queries, such as using conditional comments or JavaScript libraries.

web designmedia queriesresponsive web design
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

Recommended for you

Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices

Slides for my Adobe MAX 2011 presentation on Optimizing Sites for Mobile Devices. In this hands-on lab, I explore the concept of developing a mobile strategy that approaches mobile as an equal partner in the design process, and explores techniques to help site content deploy across devices and contexts.

media queriesmobileoptimizing
Intro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresIntro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS features

From meta viewport to @viewport and from device-pixel-ratio to the resolution media query: various responsive design hooks are undergoing standardization, allowing for future-proof sites that work well in different contexts. In addition, new CSS features like object-fit, relative length units and so on are increasingly supported by browsers as well, and allow for more versatile responsive design solutions. In my talk, I will look at these features and explain how they can be used in websites today.

sotb4responsive designmobile
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design

Designing for the web is no longer what it used to be. The number of devices with web-browsing capabilities is growing at an increasing speed. RWD is an approach aimed to provide a solid viewing experience for a multiple of screens with one set of code.

responsive designfront endweb design
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.

Recommended for you

Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18

There is no mobile Web, there is no desktop Web, and there is no tablet Web. We view the same Web just in different ways. So how do we do it? By getting rid of our fixed-width, device-specific approaches and use Responsive Web Design techniques. This session will focus on what is Responsive Web Design and how you can use his 3-pronged approach on your current apps today which will also adapt to new devices in the future.

ethan marcotteresponsive web designhtml
Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012

A presentation for WordCampNL on the importance of accessible, useable websites and how to achieve that with responsive webdesign.

wordpresswordcampwebdesign
Devon 2011-f-1 반응형 웹 디자인
Devon 2011-f-1  반응형 웹 디자인Devon 2011-f-1  반응형 웹 디자인
Devon 2011-f-1 반응형 웹 디자인

The document discusses responsive web design, which involves creating websites that automatically adapt their layout to different screen sizes and devices using flexible grids, flexible images and media, and media queries. The key ingredients of responsive web design are a flexible grid-based layout, flexible images and media that resize appropriately, and media queries which allow the application of CSS styles based on characteristics of the device. Responsive design aims to provide an optimized viewing and interaction experience across a wide range of devices without the need for separate mobile sites.

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

Recommended for you

Responsive web design
Responsive web designResponsive web design
Responsive web design

This document discusses responsive web design. It defines responsive design as adjusting a website's layout to different screen sizes and devices. Key aspects of responsive design include fluid grids that adapt to different widths, responsive images that scale appropriately, and responsive fonts whose size adjusts. Media queries allow applying CSS styles conditionally based on screen width. The ideal fluid layout works across browsers from 780px to 1260px, accommodating most users. Responsive images avoid sending large files to small devices. Responsive typography optimizes line lengths for readability.

web designipadcss
Mobile and Responsive Design with Sass
Mobile and Responsive Design with SassMobile and Responsive Design with Sass
Mobile and Responsive Design with Sass

Is your site ready for the mobile web? Are you sure? Go ahead, check it on your phone, and your kid's phone, and a tablet, and some Android dealies, and a Bleakberry. And a TV or two. I'll wait. That was an eye-opener, right? Web design and front end development has never been more complex than it is now, and it's likely to get worse before it gets better. Should you design your site "Mobile First"? How about "Adaptive" or "Responsive"? What's the difference between those again? I want to talk about why you might want to choose these approaches to your project. CSS is also not really up to the task of managing all this complexity. Sure, it *can* do it, but pure CSS strains almost to the breaking point under the pressure. So let's welcome Sass to the party. Sass is a CSS preprocessor that gives CSS authors the tools we've been aching for in creating and managing large and complex CSS projects. We'll cover a few of the Sass basics, but the real value here is in the more sophisticated tools that let you manage all the moving parts necessary in creating all this new-fangled wizardry. We'll cover: - Mobile First - Adaptive Design - Responsive Design - Stand-alone mobile options - Sass - Mobile-focused tools - Compass - Survival Kit - Susy

nyc campdrupalnyc camp 2012
Responsive design and retina displays
Responsive design and retina displaysResponsive design and retina displays
Responsive design and retina displays

These are the slides for the Austin Adobe User Group presentation on Responsive Web Design and Retina Displays on 9/14/12. The code example files are at: https://github.com/elimc/AAUG-RWD-and-Retina_9-14-12

cssresponsive web designretina display
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

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
 
Using Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetUsing Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component Set
Joseph Labrecque
 
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
Pixel Crayons
 
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
 

What's hot (19)

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
 
Creating mobile apps without native code
Creating mobile apps without native codeCreating mobile apps without native code
Creating mobile apps without native code
 
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
 
The future of media queries?
The future of media queries?The future of media queries?
The future of media queries?
 
Mobile UI Design Patterns
Mobile UI Design PatternsMobile UI Design Patterns
Mobile UI Design Patterns
 
Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!Responsive Design: Let's get Responsive!
Responsive Design: Let's get Responsive!
 
Using Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetUsing Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component Set
 
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)
 
Exploring the physical web
Exploring the physical webExploring the physical web
Exploring the physical web
 
Cm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learnCm i padwebdev_lunch_learn
Cm i padwebdev_lunch_learn
 
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
 
Web Design Trends For 2016
Web Design Trends For 2016Web Design Trends For 2016
Web Design Trends For 2016
 
Google Developer Day: State of Ajax
Google Developer Day: State of AjaxGoogle Developer Day: State of Ajax
Google Developer Day: State of Ajax
 
Explaining Ajax
Explaining AjaxExplaining Ajax
Explaining Ajax
 
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
 
Accessible Responsive Web Design
Accessible Responsive Web DesignAccessible Responsive Web Design
Accessible Responsive Web Design
 
Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]Adaptive Designs Across Devices [UXIM 2015]
Adaptive Designs Across Devices [UXIM 2015]
 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices
 
Web design and development trends
Web design and development  trendsWeb design and development  trends
Web design and development trends
 

Viewers also liked

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
 

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
 
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)
 
Wireframes for WordPress
Wireframes for WordPressWireframes for WordPress
Wireframes for WordPress
 
The Ultimate Guide to Font Pairing
The Ultimate Guide to Font PairingThe Ultimate Guide to Font Pairing
The Ultimate Guide to Font Pairing
 
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
 
An introduction to Usability
An introduction to UsabilityAn introduction to Usability
An introduction to Usability
 

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

Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Jason Harwig
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
Joe Seifi
 
Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)
Kevin Bruce
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web Design
Advancio
 
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 Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
jameswillweb
 
Intro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresIntro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS features
Andreas Bovens
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Julia Vi
 
Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18
Frédéric Harper
 
Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012
Tom Hermans
 
Devon 2011-f-1 반응형 웹 디자인
Devon 2011-f-1  반응형 웹 디자인Devon 2011-f-1  반응형 웹 디자인
Devon 2011-f-1 반응형 웹 디자인
Daum DNA
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
Zeeshan Khan
 
Mobile and Responsive Design with Sass
Mobile and Responsive Design with SassMobile and Responsive Design with Sass
Mobile and Responsive Design with Sass
nyccamp
 
Responsive design and retina displays
Responsive design and retina displaysResponsive design and retina displays
Responsive design and retina displays
Eli McMakin
 
Responsive websites. Toolbox
Responsive websites. ToolboxResponsive websites. Toolbox
Responsive websites. Toolbox
Wojtek Zając
 
There Is No Mobile: An Introduction To Responsive Web Design
There Is No Mobile: An Introduction To Responsive Web DesignThere Is No Mobile: An Introduction To Responsive Web Design
There Is No Mobile: An Introduction To Responsive Web Design
Chris Love
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web Design
Cantina
 
Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3
Zoe Gillenwater
 
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 Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Vladimir Zhidal
 

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

Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web Design
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
 
Intro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS featuresIntro to @viewport & other new Responsive Web Design CSS features
Intro to @viewport & other new Responsive Web Design CSS features
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18Responsive Web Design - Web & PHP Conference - 2013-09-18
Responsive Web Design - Web & PHP Conference - 2013-09-18
 
Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012Responsive webdesign WordCampNL 2012
Responsive webdesign WordCampNL 2012
 
Devon 2011-f-1 반응형 웹 디자인
Devon 2011-f-1  반응형 웹 디자인Devon 2011-f-1  반응형 웹 디자인
Devon 2011-f-1 반응형 웹 디자인
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Mobile and Responsive Design with Sass
Mobile and Responsive Design with SassMobile and Responsive Design with Sass
Mobile and Responsive Design with Sass
 
Responsive design and retina displays
Responsive design and retina displaysResponsive design and retina displays
Responsive design and retina displays
 
Responsive websites. Toolbox
Responsive websites. ToolboxResponsive websites. Toolbox
Responsive websites. Toolbox
 
There Is No Mobile: An Introduction To Responsive Web Design
There Is No Mobile: An Introduction To Responsive Web DesignThere Is No Mobile: An Introduction To Responsive Web Design
There Is No Mobile: An Introduction To Responsive Web Design
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web Design
 
Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3
 
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
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 

More from 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
 

More from jameswillweb (6)

Hooray Icon Fonts!
Hooray Icon Fonts!Hooray Icon Fonts!
Hooray Icon Fonts!
 
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
 
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
 
Designing Responsively with Dreamweaver
Designing Responsively with DreamweaverDesigning Responsively with Dreamweaver
Designing Responsively with Dreamweaver
 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
 

Recently uploaded

WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
RaminGhanbari2
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
Larry Smarr
 
Manual | Product | Research Presentation
Manual | Product | Research PresentationManual | Product | Research Presentation
Manual | Product | Research Presentation
welrejdoall
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
Sally Laouacheria
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
UiPathCommunity
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Bert Blevins
 
Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
ScyllaDB
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 

Recently uploaded (20)

WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
 
The Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive ComputingThe Rise of Supernetwork Data Intensive Computing
The Rise of Supernetwork Data Intensive Computing
 
Manual | Product | Research Presentation
Manual | Product | Research PresentationManual | Product | Research Presentation
Manual | Product | Research Presentation
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
 
Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 

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