SlideShare a Scribd company logo
1 of 57
Download to read offline
CSS3:
Using media queries
to improve the web
site experience
November 19, 2011
indieconf
Zoe Mickley Gillenwater | @zomigi
What I do
     Books                         Web
     Stunning CSS3:                Accessibility
     A Project-based Guide to      specialist on
     the Latest in CSS             AT&T's design
     www.stunningcss3.com          standards team
                                   Visual designer
                                   CSS developer
     Flexible Web Design:
                                   and consultant
     Creating Liquid and Elastic
     Layouts with CSS
     www.flexiblewebbook.com

                                                     2
My 7 web-enabled devices
•   3 laptops (plus 2 external monitors)
•   Android smartphone
•   iPod Touch
•   Google TV
•   Wii




                                           3
how can our sites
accommodate all this
  DIVERSITY
         ?



                       4
Introducing media queries
• Awesome new part of CSS3
• Simple way to feed different CSS based
  on characteristics of user's device
• Not:
  – for feeding styles based on browser
  – just for feeding styles based on viewport size




                                                     5
Media query syntax: internal
body {
    background: gray;
}
@media screen and (max-width:500px) {
    body {
        background: blue;
    }
}


English translation:
Make the background gray. But up to a maximum width of
500 pixels, make the background blue.
                                                         6
Media query syntax: internal
body {
    background: blue;
}
@media screen and (min-width:501px) {
    body {
        background: gray;
    }
}


English translation:
Make the background blue. But at and past the minimum width
of 501 pixels, make the background gray.
                                                              7
How it looks




               8
Media query syntax: external
Extend the existing media part of the link
element or @import rule:

<link href="narrow.css" rel="stylesheet"
media="only screen and (max-width:500px)">

@import url(narrow.css) only screen and
(max-width:500px);




                                             9
Internal media queries
Pros:                    Cons:
• No extra HTTP          • Extra kb in file size
  request(s)               for everyone to
• Not out of sight and     download
  forgotten              • Have to use
                           JavaScript to make it
                           work with old IE




                                                   10
External media queries
Pros:                     Cons:
• Smaller file size for   • Extra HTTP requests
  non-supporting          • Out of sight so could
  browsers                  be forgotten when
• Easier to keep            updating
  organized if CSS
  extensive
• Can feed to old IE
  using conditional
  comments

                                                    11
you now know media query syntax
            YAY
               !



                                  12
but that's not where the
 CHALLENGES
          are



                           13
Designing for different widths
• Create wireframe comps for placement
  of major layout areas
• Design details in browser if possible
• Focus on content
• Harder to retrofit existing design




                                          14
Structuring HTML for reorder
• Build HTML so layout pieces can be
  rearranged visually as wanted
• This is why retrofitting so difficult




                                          15
Organizing media queries for
maximum efficiency and reach
•   Internal or external?
•   Overlap or stack?
•   Which media features to test against?
•   Where to make breaking points?
•   Which dimension as starting point?
•   Workarounds for non-supporting
    browsers?


                                            16
Starting/default width

          or
   (              )
       or something
        in between




                         17
Starting with desktop styles
Pros:                      Cons:
• No extra work to         • Mobile devices may
  make majority width        have to download
  appear correctly on        unneeded desktop
  IE 6-8                     assets
• Easiest way to           • Requires separate
  retrofit existing site     style sheets or
                             JavaScript to make
                             mobile design
                             appear in IE Mobile
                             and older mobile
                             browsers
                                                   18
Starting with mobile styles
Pros:                     Cons:
• Prevents mobile         • Desktop devices
  devices from              may have to
  downloading               download unneeded
  unneeded desktop          mobile assets
  assets                  • Requires separate
• Older, non-media-         style sheets or
  query-supporting          JavaScript to make
  mobile browsers still     majority desktop
  get the mobile styles     design appear in IE
  without any extra         6-8
  work
                                                  19
Our
starting
point




           20
Very wide: awkward




                     21
Very
narrow:
awkward




          22
Wide-screen media query
/*all the other styles up here*/

@media screen and (min-width: 1200px) {
    /*styles for larger screens in here*/
}




                                            23
Add third column
@media screen and (min-width: 1200px) {
    #nav-main {
        position: fixed;
        top: 136px;
        width: 13%;
        margin: 0;
    }
    #content-main {
        width: 58%;
        margin-left: 18%;
    }
    #content-secondary { width: 20%; }
}
                                          24
Style nav as vertical menu
@media screen and (min-width: 1200px) {
    ...
    #nav-main li {
        float: none;
        margin: 0;
        }
    #nav-main a {
        -moz-border-radius: 0;
        -webkit-border-radius: 0;
        border-radius: 0;
    }
}

                                          25
Wide-screen design




                     26
Small-screen media query
/*all the other styles up here*/

@media screen and (max-width: 760px) {
    /*styles for smaller screens in here*/
}




                                             27
Remove columns from text
@media screen and (max-width: 760px) {
    h1 + p {
        -moz-column-count: 1;
        -o-column-count: 1;
        -webkit-column-count: 1;
        column-count: 1;
    }
}




                                         28
Stack feature boxes
@media screen and (max-width: 760px) {
    ...
    .feature {
        float: none;
        width: auto;
        margin: 0 0 1.6em 0;
        padding: 0 0 0 140px;
        background-position: top left;
    }
}


                                         29
Narrow-
screen
design




          30
pause for
   CAVEATS
       &
CLARIFICATIONS

                 31
Some sites would be better
served with a separate site for
mobile devices instead of
using media queries.




                                  32
Even if a separate mobile site
would be best, using media
queries is a good first step if a
separate site isn't currently
feasible.




                                    33
“The choice is not between using media queries
and creating a dedicated mobile site; the choice
is between using media queries and doing
nothing at all.”
                                      ―Jeremy Keith
                           http://adactio.com/journal/1696/



                                                              34
If you do use them, they're not
the only tool you can use—you
can add scripting as well to
further customize the content,
functionality, etc.




                                  35
Media queries are only meant
to solve the problem of
mobile's small viewports, not
all the other things that can
make mobile browsing
different (such as context,
bandwidth, etc.).


                                36
“It's making sure your layout doesn't look crap
on diff. sized screens.”
                                               ―Mark Boulton
          http://twitter.com/#!/markboulton/status/50237480368214016




                                                                       37
back to
CSS


          38
Mobile media query
/*all the other styles up here*/

@media screen and (max-width: 550px) {
    /*styles for tiny screens in here*/
}




                                          39
Non-overlapping mobile media
queries
@media screen and (min-width: 551px) and
(max-width: 760px) {
    /*styles for small screens in here*/
}
@media screen and (max-width: 550px) {
    /*styles for tiny screens in here*/
}




                                           40
Media features for mobile
min-width
max-width
device-width
min-device-width
max-device-width
orientation
min-device-pixel-ratio
 -webkit-min-device-pixel-ratio
 min--moz-device-pixel-ratio
 -o-min-device-pixel-ratio
                                  41
Changing to single column
@media screen and (max-width: 550px) {
    #content-main, #content-secondary,
    #about, #credits {
        float: none;
        width: 100%;
    }
}




                                         42
Changing feature images
@media screen and (max-width: 550px) {
    ...
    .feature { padding-left: 70px; }
    #feature-candy {
        background-image: url(icon_candy_64.png);
    }
    #feature-pastry {
        background-image: url(icon_pastry_64.png);
    }
    #feature-dessert {
        background-image: url(icon_dessert_64.png);
    }
}
                                                      43
Mobile
design




         44
Viewport meta tag
Forces mobile devices to scale viewport to
actual device width

<meta name="viewport"
      content="width=device-width, maximum-scale=1.0">




                                                     45
View it live
http://stunningcss3.com/code/bakery/




                                       46
Dealing with IE 6, 7, and 8
• Conditional comments
• JavaScript




                              47
Conditional comments
• Split styles into separate sheets and
  feed applicable sheet to IE based on
  whether it's IE on desktop or mobile
• Approach varies based on which set of
  styles are your default




                                          48
Conditional comment when
desktop styles are default
Feed mobile IE media query sheet:
<link rel="stylesheet" href="global.css" media="all">

<link rel="stylesheet" href="mobile.css" media="all
and (max-width: 700px)">

<!--[if IEMobile 7]>
<link rel="stylesheet" href="mobile.css" media="all">
<![endif]-->



Source: http://blogs.msdn.com/b/iemobile/archive/2010/12/08/targeting-mobile-
optimized-css-at-windows-phone-7.aspx                                         49
Conditional comment when
mobile styles are default
Feed older IE media query sheet, hide from
mobile IE:
<link rel="stylesheet" href="global.css" media="all">

<link rel="stylesheet" href="desktop.css" media="all
and (min-width: 700px)">

<!--[if (lt IE 9)&(!IEMobile 7)]>
<link rel="stylesheet" href="desktop.css" media="all">
<![endif]-->

Source: http://adactio.com/journal/4494/
                                                        50
Pre-fab JavaScript for non-
supporting browsers
• Simply add one of these scripts:
  – Respond:
    https://github.com/scottjehl/Respond
  – css3-mediaqueries.js:
    http://code.google.com/p/css3-
    mediaqueries-js/
• Avoid extra HTTP request for non-IE
  browsers using conditional comments:
 <!--[if (lt IE 9)&(!IEMobile 7)]>
 <script src="respond.min.js"></script>
 <![endif]-->
                                           51
WHAT ELSE
can media queries do?




                        52
Swapping images on high-res
displays
@media
screen   and   (moz--min-device-pixel-ratio : 1.5),
screen   and   (-o-min-device-pixel-ratio : 3/2),
screen   and   (-webkit-min-device-pixel-ratio : 1.5),
screen   and   (min-device-pixel-ratio : 1.5) {

}




                                                         53
Swapping images on high-res
displays
@media ... screen and (min-device-pixel-ratio : 1.5) {
    .feature {
        -moz-background-size: 64px 64px;
        -webkit-background-size: 64px 64px;
        background-size: 64px 64px;
    }
    #feature-candy {
        background-image: url(icon_candy_128.png); }
    #feature-pastry {
        background-image: url(icon_pastry_128.png); }
    #feature-dessert {
        background-image: url(icon_dessert_128.png); }
}

                                                         54
Examples of sites using media
queries
• Gallery: http://mediaqueri.es/
• My own bookmarks:
  – https://gimmebar.com/loves/zomigi/tag/
    mediaqueries
  – www.delicious.com/pixelsurge/
    nicedesign+mediaqueries
  – www.delicious.com/pixelsurge/
    nicedesign+liquid



                                             55
Learn more
Download slides and get links at
http://zomigi.com/blog/media-queries-
presentation




                                        56
Questions?




Zoe Mickley Gillenwater
@zomigi
design@zomigi.com
zomigi.com | stunningcss3.com | flexiblewebbook.com
                                                      57

More Related Content

What's hot

Bootstrap for Beginners
Bootstrap for BeginnersBootstrap for Beginners
Bootstrap for BeginnersD'arce Hess
 
Next Steps in Responsive Design
Next Steps in Responsive DesignNext Steps in Responsive Design
Next Steps in Responsive DesignJustin Avery
 
Darwin web standards
Darwin web standardsDarwin web standards
Darwin web standardsJustin Avery
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to Responsive Web DesignShawn Calvert
 
Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Zoe Gillenwater
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3Gopi A
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignSayanee Basu
 
Dynamic User Interfaces for Desktop and Mobile
Dynamic User Interfaces for Desktop and MobileDynamic User Interfaces for Desktop and Mobile
Dynamic User Interfaces for Desktop and Mobilepeychevi
 
Fundamentals of Web
Fundamentals of WebFundamentals of Web
Fundamentals of WebSabir Haque
 
Adobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + FireworksNathan Smith
 
How the Wordpress CMS Really Works
How the Wordpress CMS Really WorksHow the Wordpress CMS Really Works
How the Wordpress CMS Really WorksHandsOnWP.com
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Erin M. Kidwell
 
A Complete Guide to Frontend - UI Developer
A Complete Guide to Frontend - UI DeveloperA Complete Guide to Frontend - UI Developer
A Complete Guide to Frontend - UI Developernariyaravi
 
How WordPress Themes Work
How WordPress Themes WorkHow WordPress Themes Work
How WordPress Themes WorkHandsOnWP.com
 

What's hot (20)

Bootstrap for Beginners
Bootstrap for BeginnersBootstrap for Beginners
Bootstrap for Beginners
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Slice and Dice
Slice and DiceSlice and Dice
Slice and Dice
 
Real-world CSS3
Real-world CSS3Real-world CSS3
Real-world CSS3
 
Next Steps in Responsive Design
Next Steps in Responsive DesignNext Steps in Responsive Design
Next Steps in Responsive Design
 
Darwin web standards
Darwin web standardsDarwin web standards
Darwin web standards
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to 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
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Dynamic User Interfaces for Desktop and Mobile
Dynamic User Interfaces for Desktop and MobileDynamic User Interfaces for Desktop and Mobile
Dynamic User Interfaces for Desktop and Mobile
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
 
Roadmap 01
Roadmap 01Roadmap 01
Roadmap 01
 
Fundamentals of Web
Fundamentals of WebFundamentals of Web
Fundamentals of Web
 
Adobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + Fireworks
 
How the Wordpress CMS Really Works
How the Wordpress CMS Really WorksHow the Wordpress CMS Really Works
How the Wordpress CMS Really Works
 
Slides bootstrap-4
Slides bootstrap-4Slides bootstrap-4
Slides bootstrap-4
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
A Complete Guide to Frontend - UI Developer
A Complete Guide to Frontend - UI DeveloperA Complete Guide to Frontend - UI Developer
A Complete Guide to Frontend - UI Developer
 
How WordPress Themes Work
How WordPress Themes WorkHow WordPress Themes Work
How WordPress Themes Work
 

Viewers also liked

Hacking the next
Hacking the nextHacking the next
Hacking the nextaeioux
 
Accessible UX: Beyond the checklist to great experiences
Accessible UX: Beyond the checklist to great experiencesAccessible UX: Beyond the checklist to great experiences
Accessible UX: Beyond the checklist to great experiencesWhitney Quesenbery
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive LayoutsZoe Gillenwater
 
Deconstructing delight
Deconstructing delightDeconstructing delight
Deconstructing delightDana Chisnell
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Salesforce Developers
 
From Desktop to Home: Optimizing for Voice
From Desktop to Home: Optimizing for VoiceFrom Desktop to Home: Optimizing for Voice
From Desktop to Home: Optimizing for VoicePeter "Dr. Pete" Meyers
 

Viewers also liked (8)

Hacking the next
Hacking the nextHacking the next
Hacking the next
 
Accessible UX: Beyond the checklist to great experiences
Accessible UX: Beyond the checklist to great experiencesAccessible UX: Beyond the checklist to great experiences
Accessible UX: Beyond the checklist to great experiences
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive Layouts
 
Deconstructing delight
Deconstructing delightDeconstructing delight
Deconstructing delight
 
The World of Google: US Vs. Europe
The World of Google: US Vs. EuropeThe World of Google: US Vs. Europe
The World of Google: US Vs. Europe
 
SLDS and Lightning Components
SLDS and Lightning ComponentsSLDS and Lightning Components
SLDS and Lightning Components
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17
 
From Desktop to Home: Optimizing for Voice
From Desktop to Home: Optimizing for VoiceFrom Desktop to Home: Optimizing for Voice
From Desktop to Home: Optimizing for Voice
 

Similar to CSS3: Using media queries to improve the web site experience

Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web DesignMike Wilcox
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio
 
The Mobile Development Landscape
The Mobile Development LandscapeThe Mobile Development Landscape
The Mobile Development LandscapeAmbert Ho
 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practicesmintersam
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply ResponsiveDenise Jacobs
 
Responsive Web Design On Student's day
Responsive Web Design On Student's day Responsive Web Design On Student's day
Responsive Web Design On Student's day psophy
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oiljameswillweb
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignJulia Vi
 
Responsive Web Design (HeadStart TechTalks)
Responsive Web Design (HeadStart TechTalks)Responsive Web Design (HeadStart TechTalks)
Responsive Web Design (HeadStart TechTalks)Tirthesh Ganatra
 
Responsive web design with various grids and frameworks comparison
Responsive web design with various grids and frameworks comparisonResponsive web design with various grids and frameworks comparison
Responsive web design with various grids and frameworks comparisonDhrubaJyoti Dey
 
Responsive Web Design - Why and How
Responsive Web Design - Why and HowResponsive Web Design - Why and How
Responsive Web Design - Why and HowJudi Wunderlich
 
Responsive web designing course in Chandigarh
Responsive web designing course in Chandigarh Responsive web designing course in Chandigarh
Responsive web designing course in Chandigarh Big Boxx Animation Academy
 
An Introduction to Responsive Design
An Introduction to Responsive DesignAn Introduction to Responsive Design
An Introduction to Responsive DesignValtech UK
 
Responsive web design
Responsive web designResponsive web design
Responsive web designBen MacNeill
 
Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Kevin Bruce
 
BarkleyREI & Hannon Hill Webinar - Responsive Web Design
BarkleyREI & Hannon Hill Webinar - Responsive Web DesignBarkleyREI & Hannon Hill Webinar - Responsive Web Design
BarkleyREI & Hannon Hill Webinar - Responsive Web Designhannonhill
 
Building Responsive Websites with the Bootstrap 3 Framework
Building Responsive Websites with the Bootstrap 3 FrameworkBuilding Responsive Websites with the Bootstrap 3 Framework
Building Responsive Websites with the Bootstrap 3 FrameworkWebvanta
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereUsing Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereChris Love
 

Similar to CSS3: Using media queries to improve the web site experience (20)

Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web Design
 
The Mobile Development Landscape
The Mobile Development LandscapeThe Mobile Development Landscape
The Mobile Development Landscape
 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices
 
Mobile web development
Mobile web development Mobile web development
Mobile web development
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply Responsive
 
Responsive Web Design On Student's day
Responsive Web Design On Student's day Responsive Web Design On Student's day
Responsive Web Design On Student's day
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Responsive Web Design (HeadStart TechTalks)
Responsive Web Design (HeadStart TechTalks)Responsive Web Design (HeadStart TechTalks)
Responsive Web Design (HeadStart TechTalks)
 
Responsive web design with various grids and frameworks comparison
Responsive web design with various grids and frameworks comparisonResponsive web design with various grids and frameworks comparison
Responsive web design with various grids and frameworks comparison
 
Responsive Web Design - Why and How
Responsive Web Design - Why and HowResponsive Web Design - Why and How
Responsive Web Design - Why and How
 
Responsive web designing course in Chandigarh
Responsive web designing course in Chandigarh Responsive web designing course in Chandigarh
Responsive web designing course in Chandigarh
 
An Introduction to Responsive Design
An Introduction to Responsive DesignAn Introduction to Responsive Design
An Introduction to Responsive Design
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)Responsive Development (ZendCon 2012)
Responsive Development (ZendCon 2012)
 
Responsive web - CC FE & UX
Responsive web -  CC FE & UXResponsive web -  CC FE & UX
Responsive web - CC FE & UX
 
BarkleyREI & Hannon Hill Webinar - Responsive Web Design
BarkleyREI & Hannon Hill Webinar - Responsive Web DesignBarkleyREI & Hannon Hill Webinar - Responsive Web Design
BarkleyREI & Hannon Hill Webinar - Responsive Web Design
 
Building Responsive Websites with the Bootstrap 3 Framework
Building Responsive Websites with the Bootstrap 3 FrameworkBuilding Responsive Websites with the Bootstrap 3 Framework
Building Responsive Websites with the Bootstrap 3 Framework
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereUsing Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere
 

More from Zoe Gillenwater

Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Zoe Gillenwater
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Zoe Gillenwater
 
Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Zoe Gillenwater
 
Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Zoe Gillenwater
 
Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)Zoe Gillenwater
 
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)Zoe Gillenwater
 
Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)Zoe Gillenwater
 
Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)Zoe Gillenwater
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Zoe Gillenwater
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (Generate Conf)
CSS Lessons Learned the Hard Way (Generate Conf)CSS Lessons Learned the Hard Way (Generate Conf)
CSS Lessons Learned the Hard Way (Generate Conf)Zoe Gillenwater
 
Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Zoe Gillenwater
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Zoe Gillenwater
 
Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)Zoe Gillenwater
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Zoe Gillenwater
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into PracticeZoe Gillenwater
 
The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS LayoutZoe Gillenwater
 

More from Zoe Gillenwater (20)

Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)
 
Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)
 
Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)
 
Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)
 
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
 
Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)
 
Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)
 
CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)
 
CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)
 
CSS Lessons Learned the Hard Way (Generate Conf)
CSS Lessons Learned the Hard Way (Generate Conf)CSS Lessons Learned the Hard Way (Generate Conf)
CSS Lessons Learned the Hard Way (Generate Conf)
 
Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)
 
Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into Practice
 
CSS3 Layout
CSS3 LayoutCSS3 Layout
CSS3 Layout
 
The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS Layout
 

Recently uploaded

Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Associazione Digital Days
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxKevinYaelJimnezSanti
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioRMG Project Studio
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyChristopher Totten
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Yantram Animation Studio Corporation
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppNadaMohammed714321
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...Pranav Subramanian
 
10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024digital learning point
 
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONPORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONAnastasiya Kudinova
 
Piece by Piece Magazine
Piece by Piece Magazine                      Piece by Piece Magazine
Piece by Piece Magazine CharlottePulte
 
PORTFOLIO 2024 ANASTASIYA KUDINOVA
PORTFOLIO 2024       ANASTASIYA KUDINOVAPORTFOLIO 2024       ANASTASIYA KUDINOVA
PORTFOLIO 2024 ANASTASIYA KUDINOVAAnastasiya Kudinova
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinSamar Hossam ElDin Ahmed
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks CharlottePulte
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designersPixeldarts
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssNadaMohammed714321
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfLucyBonelli
 
Imagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioImagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioAlinaLau2
 
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Thomas Schielke
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfAlasAlthaher
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...Pranav Subramanian
 

Recently uploaded (20)

Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptx
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project Studio
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenology
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 ppppppppppppppp
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
 
10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024
 
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONPORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
 
Piece by Piece Magazine
Piece by Piece Magazine                      Piece by Piece Magazine
Piece by Piece Magazine
 
PORTFOLIO 2024 ANASTASIYA KUDINOVA
PORTFOLIO 2024       ANASTASIYA KUDINOVAPORTFOLIO 2024       ANASTASIYA KUDINOVA
PORTFOLIO 2024 ANASTASIYA KUDINOVA
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssss
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
 
Imagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioImagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering Portfolio
 
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdf
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
 

CSS3: Using media queries to improve the web site experience

  • 1. CSS3: Using media queries to improve the web site experience November 19, 2011 indieconf Zoe Mickley Gillenwater | @zomigi
  • 2. What I do Books Web Stunning CSS3: Accessibility A Project-based Guide to specialist on the Latest in CSS AT&T's design www.stunningcss3.com standards team Visual designer CSS developer Flexible Web Design: and consultant Creating Liquid and Elastic Layouts with CSS www.flexiblewebbook.com 2
  • 3. My 7 web-enabled devices • 3 laptops (plus 2 external monitors) • Android smartphone • iPod Touch • Google TV • Wii 3
  • 4. how can our sites accommodate all this DIVERSITY ? 4
  • 5. Introducing media queries • Awesome new part of CSS3 • Simple way to feed different CSS based on characteristics of user's device • Not: – for feeding styles based on browser – just for feeding styles based on viewport size 5
  • 6. Media query syntax: internal body { background: gray; } @media screen and (max-width:500px) { body { background: blue; } } English translation: Make the background gray. But up to a maximum width of 500 pixels, make the background blue. 6
  • 7. Media query syntax: internal body { background: blue; } @media screen and (min-width:501px) { body { background: gray; } } English translation: Make the background blue. But at and past the minimum width of 501 pixels, make the background gray. 7
  • 9. Media query syntax: external Extend the existing media part of the link element or @import rule: <link href="narrow.css" rel="stylesheet" media="only screen and (max-width:500px)"> @import url(narrow.css) only screen and (max-width:500px); 9
  • 10. Internal media queries Pros: Cons: • No extra HTTP • Extra kb in file size request(s) for everyone to • Not out of sight and download forgotten • Have to use JavaScript to make it work with old IE 10
  • 11. External media queries Pros: Cons: • Smaller file size for • Extra HTTP requests non-supporting • Out of sight so could browsers be forgotten when • Easier to keep updating organized if CSS extensive • Can feed to old IE using conditional comments 11
  • 12. you now know media query syntax YAY ! 12
  • 13. but that's not where the CHALLENGES are 13
  • 14. Designing for different widths • Create wireframe comps for placement of major layout areas • Design details in browser if possible • Focus on content • Harder to retrofit existing design 14
  • 15. Structuring HTML for reorder • Build HTML so layout pieces can be rearranged visually as wanted • This is why retrofitting so difficult 15
  • 16. Organizing media queries for maximum efficiency and reach • Internal or external? • Overlap or stack? • Which media features to test against? • Where to make breaking points? • Which dimension as starting point? • Workarounds for non-supporting browsers? 16
  • 17. Starting/default width or ( ) or something in between 17
  • 18. Starting with desktop styles Pros: Cons: • No extra work to • Mobile devices may make majority width have to download appear correctly on unneeded desktop IE 6-8 assets • Easiest way to • Requires separate retrofit existing site style sheets or JavaScript to make mobile design appear in IE Mobile and older mobile browsers 18
  • 19. Starting with mobile styles Pros: Cons: • Prevents mobile • Desktop devices devices from may have to downloading download unneeded unneeded desktop mobile assets assets • Requires separate • Older, non-media- style sheets or query-supporting JavaScript to make mobile browsers still majority desktop get the mobile styles design appear in IE without any extra 6-8 work 19
  • 23. Wide-screen media query /*all the other styles up here*/ @media screen and (min-width: 1200px) { /*styles for larger screens in here*/ } 23
  • 24. Add third column @media screen and (min-width: 1200px) { #nav-main { position: fixed; top: 136px; width: 13%; margin: 0; } #content-main { width: 58%; margin-left: 18%; } #content-secondary { width: 20%; } } 24
  • 25. Style nav as vertical menu @media screen and (min-width: 1200px) { ... #nav-main li { float: none; margin: 0; } #nav-main a { -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; } } 25
  • 27. Small-screen media query /*all the other styles up here*/ @media screen and (max-width: 760px) { /*styles for smaller screens in here*/ } 27
  • 28. Remove columns from text @media screen and (max-width: 760px) { h1 + p { -moz-column-count: 1; -o-column-count: 1; -webkit-column-count: 1; column-count: 1; } } 28
  • 29. Stack feature boxes @media screen and (max-width: 760px) { ... .feature { float: none; width: auto; margin: 0 0 1.6em 0; padding: 0 0 0 140px; background-position: top left; } } 29
  • 31. pause for CAVEATS & CLARIFICATIONS 31
  • 32. Some sites would be better served with a separate site for mobile devices instead of using media queries. 32
  • 33. Even if a separate mobile site would be best, using media queries is a good first step if a separate site isn't currently feasible. 33
  • 34. “The choice is not between using media queries and creating a dedicated mobile site; the choice is between using media queries and doing nothing at all.” ―Jeremy Keith http://adactio.com/journal/1696/ 34
  • 35. If you do use them, they're not the only tool you can use—you can add scripting as well to further customize the content, functionality, etc. 35
  • 36. Media queries are only meant to solve the problem of mobile's small viewports, not all the other things that can make mobile browsing different (such as context, bandwidth, etc.). 36
  • 37. “It's making sure your layout doesn't look crap on diff. sized screens.” ―Mark Boulton http://twitter.com/#!/markboulton/status/50237480368214016 37
  • 39. Mobile media query /*all the other styles up here*/ @media screen and (max-width: 550px) { /*styles for tiny screens in here*/ } 39
  • 40. Non-overlapping mobile media queries @media screen and (min-width: 551px) and (max-width: 760px) { /*styles for small screens in here*/ } @media screen and (max-width: 550px) { /*styles for tiny screens in here*/ } 40
  • 41. Media features for mobile min-width max-width device-width min-device-width max-device-width orientation min-device-pixel-ratio -webkit-min-device-pixel-ratio min--moz-device-pixel-ratio -o-min-device-pixel-ratio 41
  • 42. Changing to single column @media screen and (max-width: 550px) { #content-main, #content-secondary, #about, #credits { float: none; width: 100%; } } 42
  • 43. Changing feature images @media screen and (max-width: 550px) { ... .feature { padding-left: 70px; } #feature-candy { background-image: url(icon_candy_64.png); } #feature-pastry { background-image: url(icon_pastry_64.png); } #feature-dessert { background-image: url(icon_dessert_64.png); } } 43
  • 45. Viewport meta tag Forces mobile devices to scale viewport to actual device width <meta name="viewport" content="width=device-width, maximum-scale=1.0"> 45
  • 47. Dealing with IE 6, 7, and 8 • Conditional comments • JavaScript 47
  • 48. Conditional comments • Split styles into separate sheets and feed applicable sheet to IE based on whether it's IE on desktop or mobile • Approach varies based on which set of styles are your default 48
  • 49. Conditional comment when desktop styles are default Feed mobile IE media query sheet: <link rel="stylesheet" href="global.css" media="all"> <link rel="stylesheet" href="mobile.css" media="all and (max-width: 700px)"> <!--[if IEMobile 7]> <link rel="stylesheet" href="mobile.css" media="all"> <![endif]--> Source: http://blogs.msdn.com/b/iemobile/archive/2010/12/08/targeting-mobile- optimized-css-at-windows-phone-7.aspx 49
  • 50. Conditional comment when mobile styles are default Feed older IE media query sheet, hide from mobile IE: <link rel="stylesheet" href="global.css" media="all"> <link rel="stylesheet" href="desktop.css" media="all and (min-width: 700px)"> <!--[if (lt IE 9)&(!IEMobile 7)]> <link rel="stylesheet" href="desktop.css" media="all"> <![endif]--> Source: http://adactio.com/journal/4494/ 50
  • 51. Pre-fab JavaScript for non- supporting browsers • Simply add one of these scripts: – Respond: https://github.com/scottjehl/Respond – css3-mediaqueries.js: http://code.google.com/p/css3- mediaqueries-js/ • Avoid extra HTTP request for non-IE browsers using conditional comments: <!--[if (lt IE 9)&(!IEMobile 7)]> <script src="respond.min.js"></script> <![endif]--> 51
  • 52. WHAT ELSE can media queries do? 52
  • 53. Swapping images on high-res displays @media screen and (moz--min-device-pixel-ratio : 1.5), screen and (-o-min-device-pixel-ratio : 3/2), screen and (-webkit-min-device-pixel-ratio : 1.5), screen and (min-device-pixel-ratio : 1.5) { } 53
  • 54. Swapping images on high-res displays @media ... screen and (min-device-pixel-ratio : 1.5) { .feature { -moz-background-size: 64px 64px; -webkit-background-size: 64px 64px; background-size: 64px 64px; } #feature-candy { background-image: url(icon_candy_128.png); } #feature-pastry { background-image: url(icon_pastry_128.png); } #feature-dessert { background-image: url(icon_dessert_128.png); } } 54
  • 55. Examples of sites using media queries • Gallery: http://mediaqueri.es/ • My own bookmarks: – https://gimmebar.com/loves/zomigi/tag/ mediaqueries – www.delicious.com/pixelsurge/ nicedesign+mediaqueries – www.delicious.com/pixelsurge/ nicedesign+liquid 55
  • 56. Learn more Download slides and get links at http://zomigi.com/blog/media-queries- presentation 56
  • 57. Questions? Zoe Mickley Gillenwater @zomigi design@zomigi.com zomigi.com | stunningcss3.com | flexiblewebbook.com 57