SlideShare a Scribd company logo
CSS3 Lightning Talk
  Media Queries
& Kick Start for Mobile
by Jordan McCullough
Preparing
for Mobile
Liquid Layout


Proportional Sizing
Percent dimensions for block elements


navigation{ width: 100%; }
content{ width: 80%; float: left}
aside{ width: 20%; float: left}
Proportional EMs for font sizes

h1 { font-size: 2.3em }
p { font-size: 1em }
article{ font-size: .9em}
Maximize use of background images


#logo {
  background: url(logo.png);
}
Retooling the
HTML Viewport
Layout Viewport


     Visual
   Viewport
Layout Viewport


                       Visual
                     Viewport




<meta nam
                    {
          e=”viewport” cont
                           ent=”w i dth=device-w i d
                                                     th”>
As web developers, we only care about how


content will fit
in the device’s screen size
Force browser to
             report width the same
                as device width

<meta name="viewport"

content="width=device-width,

maximum-scale=1">
                      Optional:
                   initial-scale=1,
                  user-scalable=no
Viewport Objectives

✓ Establish expected widths for content

✓ Override default reported size on mobiles

 ✓   Constrain user zooming and scaling
The Media Query
@media only all a
@media only all and [(m
media only all and [(media
ia only all and [(media fea
and [(media feature)]
and [(media feature)]
      (width: 500px)
   (min-width: 300px)
 and (max-width: 500px)
and (device-pixel-ratio: 2)
Device Pixel Ratio
Device Pixels
1   2   3     4   5      6   7   8




            CSS Pixels
        1     2   3      4
What happens if...
               device-pixel-ratio == 1




  ImageA.png




         device-pixel-ratio > 1
                                    ImageA.png
Maximize use of high pixel density displays
   Minimize image downloads per platform


@media only all and
(min-device-pixel-ratio: 2){
  #myBackground{
    background: url(bg.png);
    background-size: 50% 50%;
  }
}
✓ Separate stylesheet for high density displays

✓   Produce images scales by pixel-ratio



✓   Write CSS-to-device px compensation
Best Practices
Best Practices


#1   Keep platform rules in
     separate stylesheets
Best Practices


#2    Apply media query features to
      value ranges using min- and max-
Best Practices

      Supply a core stylesheet that
#3    maintains a
      independent
                 ppearance that is
                   of media queries
Thank You
Email:   jordanm@ambientideas.com

Twitter: @ambientphoto

Online: http://www.ambientideas.com

More Related Content

CSS3 Media Queries & Kick Start for Mobile