SlideShare a Scribd company logo
1 of 71
Download to read offline
Building
                   Responsive
                      Layouts
                   by Zoe Mickley Gillenwater
                                    @zomigi
                                  zomigi.com


December 5, 2012
CSS Dev Conf
hello
nice to meet you



                   2
I don’t use a
mobile phone
I have a
process for
eating these

          why
responsive web design works



                              5
         
 what      why
responsive web design means



                              6
                 ?
what      why       how
to do responsive web design



                              7
fluid/liquid layout
uses percentage widths to adapt
      to size of viewport



                                  8
Look at this!
This is so tough!
I'm in such peril
  way up here!




                    9
Oh, wait…




            10
How do
we make
this fluid?




              11
Start with fluid wrapper




                           12
Add opposing floats inside




                             13
3 cols with poor source order




                                14
Nest 2-col layout in 2-col layout




                                    15
Percentages are relative




                           16
Determining nested widths
 width of column
you want to match   ÷      width of
                        parent column   =      width of
                                            nested column




                                                            17
Determining nested widths
 width of column
you want to match   ÷      width of
                        parent column   =      width of
                                            nested column


       target       ÷     context       =    result




                                                            18
Determining nested widths
 width of column
you want to match   ÷      width of
                        parent column   =      width of
                                            nested column


       target       ÷     context       =    result


         20         ÷       80          =      .25
                                            which means
                                              25%

                                                            19
That's more like it




                      20
What about fluid grids?




                          21
Width of this nested block?




                              22
Well that's not right…




                         23
To the laboratory!
 width of column
you want to match   ÷      width of
                        parent column   =      width of
                                            nested column


       target       ÷     context       =    result


         25         ÷      62.5         =       .4
                                            which means
                                              40%

                                                            24
There we go




              25
                   ?
widths             spacing
between and in fluid columns



                               26
Leave a gap via widths




                         27
Declaring fluid margin/padding
• Adjust widths so everything adds to 100%
  • For IE 6/7, make it 99%: avoids problems due
    to rounding % to px
• Nesting affects margin/padding values too
  • Use target÷context formula to match outer
    spacing with inner spacing




                                                   28
Using box-sizing
• Makes px & em margin/padding on fluid
  layout easy
• Standard box model
  • box-sizing: content-box
  • Padding & border added on to width/height
• New box model
  • box-sizing: border-box
  • Padding & border subtracted from width/height


                                                    29
Fluid grid, fixed-width spacing
.column {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  padding: 0 20px;                  Subtracted
}
                                    from width in
                                    border-box
                                    box model


                                                    30
Use border as faux margin
.column {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  padding: 0 20px;
  border-left: 10px solid rgba(0,0,0,0);
  -moz-background-clip: padding-box;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
}

                   Prevents background from
                   displaying under border    31
Negate “margin” at start of row
.column {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  padding: 0 20px;
  border-left: 10px solid rgba(0,0,0,0);
  -moz-background-clip: padding-box;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
}
.row {
  margin-left: -10px;      Removes gap to
}                          left of first column   32
Fix box-sizing in IE 7 and 6
• Feed different dimensions based on
  content-box-model, or
• Use Christian Schaefer's box-sizing polyfill
  https://github.com/Schepp/box-sizing-polyfill
  .column {
    box-sizing: border-box;
    *behavior: url(boxsizing.htc);
  }



                                                  33
I recommend gridpak.com




                          34
                    ?
 fluid              hybrid
one+ column flexible, one+ not



                                 35
Hybrid layout options
• Easy: sidebars first in HTML
  • Float sidebars, main content moves up
    between floats
  • But usually not option in responsive design
• Tricky: main content first in HTML
  • Need to float it, but with what width?
  • One solution: negative margins




                                                  36
Fixed-width
sidebar
starting point




                 37
Add wrapper
with padding
#content-wrapper {
  padding-right: 290px;
}




                          38
Lay out main
content div
#content-main {
  float: left;
  width: 100%;
}




                  39
Float sidebar
#content-secondary {
  float: right;
  width: 250px;
}




                       40
A positive right margin



                   150px




                           41
A negative right margin



                      -150px




                               42
Pull sidebar into gap
#content-secondary {
  float: right;
  width: 250px;
  margin-right: -290px;   Matches
}                         wrapper’s
                          right padding,
                          just negative




                                           43
Success!




           44
To make sidebar show in IE 6
#content-wrapper {
  zoom: 1;             Adds hasLayout
}
#content-main,
#content-secondary {
  display: inline;     Hell if I know,
}                      it just works




                                         45
3-column hybrid layout
• Nest one 2-column layout inside another
• Components of each layout:
  1. Wrapper with padding on one side
  2. Fixed-width sidebar
    •   Same width as padding (or smaller)
    •   Floated same direction as padding
    •   Negative margin matching padding on same side
  3. Fluid column
    •   Floated opposite direction
    •   Width 100%

                                                        46
                 ?
fluid layout    media queries
 feed different styles based on
          viewport size

                                  47
Choosing default styles
•   Start "mobile," layer on wider styles?
•   Start "desktop," layer on narrower styles?
•   Start somewhere in between, layer on both?
•   Learn full pros/cons:
    www.zomigi.com/blog/essential-considerations-
    crafting-quality-media-queries




                                                    48
Starting
in the
middle




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

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




                                            50
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%; }
}
                                          51
Style nav as vertical menu
@media screen and (min-width: 1200px) {
    ...
    #nav-main li {
        float: none;               Stack   links
        margin: 0;
        }
    #nav-main a {
        -moz-border-radius: 0;
        -webkit-border-radius: 0;
        border-radius: 0;        Less tab-like
    }
}

                                                   52
Wide-screen design




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

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




                                             54
Things to fix
too few words per line,
so make all one column




   each too narrow,
 so stack instead and
    put pic on left



                          55
Narrow-
screen
design




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

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




                                          57
Non-overlapping version
@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*/
}




                                           58
Changing to single column
@media screen and (max-width: 550px) {
    #content-main, #content-secondary,
    #about, #credits {
        float: none;
        width: 100%;
    }
}




                                         59
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);
    }
}
                                                      60
Mobile
design




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

<meta name="viewport"
   content="width=device-width">




                                             62
Fix iOS zoom problems
<meta name="viewport"
   content="width=device-width, initial-scale=1">
<script src="ios-orientationchange-fix.js">


• Add initial-scale=1 to make page
  reflow when you switch to landscape
• Add script to fix over-zoom bug that crops
  right side of page when you switch
  • See http://filamentgroup.com/lab/a_fix_for_
    the_ios_orientationchange_zoom_bug/

                                                  63
Double-up inside the CSS
Add @viewport rule, upcoming standard,
inside style sheet:
@-moz-viewport{ width:device-width }
@-ms-viewport{ width:device-width }
@-o-viewport{ width:device-width }
@-webkit-viewport{ width:device-width }
@viewport{ width:device-width }




                                         64
conditional
 comments      or   JavaScript
  to deal with IE 8 and earlier


                                  65
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




                                               66
Conditional comment when
desktop styles are default
Feed IE Mobile 7 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                                         67
Conditional comment when
mobile styles are default
Feed older IE media query sheet, hide from
IE Mobile 7:
<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/
                                                        68
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-old-IE
  browsers using conditional comments:
 <!--[if (lt IE 9)&(!IEMobile 7)]>
 <script src="respond.min.js"></script>
 <![endif]-->


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




                                       70
Learn more
Download slides and get links at
http://bit.ly/rwdlayout



Zoe Mickley Gillenwater
@zomigi
design@zomigi.com
zomigi.com | stunningcss3.com | flexiblewebbook.com
Photo credits:
“023 Tape measure 006” by Steve James (http://www.flickr.com/photos/steeljam/3350481764/)
“Phone Booths” by Kristin Nador (http://www.flickr.com/photos/kristinnador/7744274382/)
“Reese’s Pieces” by Dave Brown (http://www.flickr.com/photos/taids/2143865543/)
“Frank on the main wall” by Justin Johnson (http://www.flickr.com/photos/justinjohnsen/4512815628/)   71

More Related Content

What's hot

Representation of Integers
Representation of IntegersRepresentation of Integers
Representation of IntegersSusantha Herath
 
Error Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksError Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksNt Arvind
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive WebsitesJoe Seifi
 
Lec 02 data representation part 1
Lec 02 data representation part 1Lec 02 data representation part 1
Lec 02 data representation part 1Abdul Khan
 
Topic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptxTopic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptxUrjaDhabarde
 
CSS Positioning and Features of CSS3
CSS Positioning and Features of CSS3CSS Positioning and Features of CSS3
CSS Positioning and Features of CSS3Jaimin Brahmbhatt
 
Introduction to the Binary Number System
Introduction to the Binary Number SystemIntroduction to the Binary Number System
Introduction to the Binary Number SystemJames Hamilton
 
RFID Based Library Management System
RFID Based Library Management SystemRFID Based Library Management System
RFID Based Library Management Systemrabeena tasleem
 
Serial vs Parallel communication & Synchronous and Asynchronous transmission
Serial vs Parallel communication & Synchronous and Asynchronous transmissionSerial vs Parallel communication & Synchronous and Asynchronous transmission
Serial vs Parallel communication & Synchronous and Asynchronous transmissionRohanMistry15
 
raster and random scan
raster and random scanraster and random scan
raster and random scanSonia Pahuja
 
Introduction to CSS Grid Layout
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid LayoutRachel Andrew
 
AES-Advanced Encryption Standard
AES-Advanced Encryption StandardAES-Advanced Encryption Standard
AES-Advanced Encryption StandardPrince Rachit
 
Digital & analog transmission
Digital & analog transmissionDigital & analog transmission
Digital & analog transmissionJeffery Vava
 

What's hot (20)

Representation of Integers
Representation of IntegersRepresentation of Integers
Representation of Integers
 
Error Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksError Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networks
 
4. block coding
4. block coding 4. block coding
4. block coding
 
B+ tree
B+ treeB+ tree
B+ tree
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
Lec 02 data representation part 1
Lec 02 data representation part 1Lec 02 data representation part 1
Lec 02 data representation part 1
 
Topic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptxTopic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptx
 
CSS Positioning and Features of CSS3
CSS Positioning and Features of CSS3CSS Positioning and Features of CSS3
CSS Positioning and Features of CSS3
 
Introduction to the Binary Number System
Introduction to the Binary Number SystemIntroduction to the Binary Number System
Introduction to the Binary Number System
 
RFID Based Library Management System
RFID Based Library Management SystemRFID Based Library Management System
RFID Based Library Management System
 
B tree
B treeB tree
B tree
 
Data compression
Data compressionData compression
Data compression
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
Serial vs Parallel communication & Synchronous and Asynchronous transmission
Serial vs Parallel communication & Synchronous and Asynchronous transmissionSerial vs Parallel communication & Synchronous and Asynchronous transmission
Serial vs Parallel communication & Synchronous and Asynchronous transmission
 
raster and random scan
raster and random scanraster and random scan
raster and random scan
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Introduction to CSS Grid Layout
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid Layout
 
AES-Advanced Encryption Standard
AES-Advanced Encryption StandardAES-Advanced Encryption Standard
AES-Advanced Encryption Standard
 
Digital & analog transmission
Digital & analog transmissionDigital & analog transmission
Digital & analog transmission
 
What is TLS/SSL?
What is TLS/SSL? What is TLS/SSL?
What is TLS/SSL?
 

Viewers also liked

Rethinking the Mobile Web by Yiibu
Rethinking the Mobile Web by YiibuRethinking the Mobile Web by Yiibu
Rethinking the Mobile Web by YiibuBryan Rieger
 
Hacking the next
Hacking the nextHacking the next
Hacking the nextaeioux
 
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 experienceZoe Gillenwater
 
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
 
Understanding & Designing for the Mobile Web
Understanding & Designing for the Mobile WebUnderstanding & Designing for the Mobile Web
Understanding & Designing for the Mobile WebWebFX
 
Deconstructing delight
Deconstructing delightDeconstructing delight
Deconstructing delightDana Chisnell
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive LayoutsZoe Gillenwater
 
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
 
深入淺出RWD自適應網頁設計
深入淺出RWD自適應網頁設計深入淺出RWD自適應網頁設計
深入淺出RWD自適應網頁設計Marie Chang
 
Android vs iPhone - Differences in UI Patterns and Design
Android vs iPhone - Differences in UI Patterns and DesignAndroid vs iPhone - Differences in UI Patterns and Design
Android vs iPhone - Differences in UI Patterns and DesignJeremy Johnson
 
Design Process in the Responsive Age
Design Process in the Responsive AgeDesign Process in the Responsive Age
Design Process in the Responsive AgePon Kattera
 
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 (15)

Rethinking the Mobile Web by Yiibu
Rethinking the Mobile Web by YiibuRethinking the Mobile Web by Yiibu
Rethinking the Mobile Web by Yiibu
 
Hacking the next
Hacking the nextHacking the next
Hacking the next
 
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
 
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
 
Understanding & Designing for the Mobile Web
Understanding & Designing for the Mobile WebUnderstanding & Designing for the Mobile Web
Understanding & Designing for the Mobile Web
 
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 Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive Layouts
 
響應式網頁教學
響應式網頁教學響應式網頁教學
響應式網頁教學
 
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
 
深入淺出RWD自適應網頁設計
深入淺出RWD自適應網頁設計深入淺出RWD自適應網頁設計
深入淺出RWD自適應網頁設計
 
Android vs iPhone - Differences in UI Patterns and Design
Android vs iPhone - Differences in UI Patterns and DesignAndroid vs iPhone - Differences in UI Patterns and Design
Android vs iPhone - Differences in UI Patterns and Design
 
Design Process in the Responsive Age
Design Process in the Responsive AgeDesign Process in the Responsive Age
Design Process in the Responsive Age
 
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 Building Responsive Layouts

The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS LayoutZoe Gillenwater
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)elliando dias
 
Flexbox every developers dream
Flexbox every developers dreamFlexbox every developers dream
Flexbox every developers dream2019gracesmith
 
JavaFX Layout Secrets with Amy Fowler
JavaFX Layout Secrets with Amy FowlerJavaFX Layout Secrets with Amy Fowler
JavaFX Layout Secrets with Amy FowlerStephen Chin
 
What is grid system
What is grid systemWhat is grid system
What is grid systemchetankane
 
Mobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardMobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardAndiNurkholis1
 
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...BookNet Canada
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSRachel Andrew
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Rachel Andrew
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsFITC
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & FriendsRachel Andrew
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using cssDhairya Joshi
 

Similar to Building Responsive Layouts (20)

The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS Layout
 
CSS3 Layout
CSS3 LayoutCSS3 Layout
CSS3 Layout
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)
 
Ppt ch06
Ppt ch06Ppt ch06
Ppt ch06
 
Ppt ch06
Ppt ch06Ppt ch06
Ppt ch06
 
Flexbox every developers dream
Flexbox every developers dreamFlexbox every developers dream
Flexbox every developers dream
 
JavaFX Layout Secrets with Amy Fowler
JavaFX Layout Secrets with Amy FowlerJavaFX Layout Secrets with Amy Fowler
JavaFX Layout Secrets with Amy Fowler
 
CSS in all its Glory
CSS in all its GloryCSS in all its Glory
CSS in all its Glory
 
Layouts
Layouts Layouts
Layouts
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
What is grid system
What is grid systemWhat is grid system
What is grid system
 
Mobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardMobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image Card
 
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and Friends
 
CSS
CSSCSS
CSS
 
CSS Systems
CSS SystemsCSS Systems
CSS Systems
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using css
 

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
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignZoe 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, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
Web Accessibility
Web AccessibilityWeb Accessibility
Web Accessibility
 

Recently uploaded

General Knowledge Quiz Game C++ CODE.pptx
General Knowledge Quiz Game C++ CODE.pptxGeneral Knowledge Quiz Game C++ CODE.pptx
General Knowledge Quiz Game C++ CODE.pptxmarckustrevion
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxKevinYaelJimnezSanti
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书zdzoqco
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptJIT KUMAR GUPTA
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfLucyBonelli
 
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
 
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...Rishabh Aryan
 
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道yrolcks
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptMaryamAfzal41
 
Color Theory Explained for Noobs- Think360 Studio
Color Theory Explained for Noobs- Think360 StudioColor Theory Explained for Noobs- Think360 Studio
Color Theory Explained for Noobs- Think360 StudioThink360 Studio
 
group_15_empirya_p1projectIndustrial.pdf
group_15_empirya_p1projectIndustrial.pdfgroup_15_empirya_p1projectIndustrial.pdf
group_15_empirya_p1projectIndustrial.pdfneelspinoy
 
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptx
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptxUnit1_Syllbwbnwnwneneneneneneentation_Sem2.pptx
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptxNitish292041
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfAayushChavan5
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssNadaMohammed714321
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks CharlottePulte
 
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster1508 A/S
 
Pearl Disrtrict urban analyusis study pptx
Pearl Disrtrict urban analyusis study pptxPearl Disrtrict urban analyusis study pptx
Pearl Disrtrict urban analyusis study pptxDanielTamiru4
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic global solution
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIyuj
 
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
 

Recently uploaded (20)

General Knowledge Quiz Game C++ CODE.pptx
General Knowledge Quiz Game C++ CODE.pptxGeneral Knowledge Quiz Game C++ CODE.pptx
General Knowledge Quiz Game C++ CODE.pptx
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptx
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
 
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
 
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
 
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道
怎么办理英国Newcastle毕业证纽卡斯尔大学学位证书一手渠道
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis ppt
 
Color Theory Explained for Noobs- Think360 Studio
Color Theory Explained for Noobs- Think360 StudioColor Theory Explained for Noobs- Think360 Studio
Color Theory Explained for Noobs- Think360 Studio
 
group_15_empirya_p1projectIndustrial.pdf
group_15_empirya_p1projectIndustrial.pdfgroup_15_empirya_p1projectIndustrial.pdf
group_15_empirya_p1projectIndustrial.pdf
 
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptx
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptxUnit1_Syllbwbnwnwneneneneneneentation_Sem2.pptx
Unit1_Syllbwbnwnwneneneneneneentation_Sem2.pptx
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdf
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssss
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks
 
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
 
Pearl Disrtrict urban analyusis study pptx
Pearl Disrtrict urban analyusis study pptxPearl Disrtrict urban analyusis study pptx
Pearl Disrtrict urban analyusis study pptx
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing services
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AI
 
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...
 

Building Responsive Layouts

  • 1. Building Responsive Layouts by Zoe Mickley Gillenwater @zomigi zomigi.com December 5, 2012 CSS Dev Conf
  • 3. I don’t use a mobile phone
  • 4. I have a process for eating these
  • 5. why responsive web design works 5
  • 6.  what why responsive web design means 6
  • 7.  ? what why how to do responsive web design 7
  • 8. fluid/liquid layout uses percentage widths to adapt to size of viewport 8
  • 9. Look at this! This is so tough! I'm in such peril way up here! 9
  • 11. How do we make this fluid? 11
  • 12. Start with fluid wrapper 12
  • 13. Add opposing floats inside 13
  • 14. 3 cols with poor source order 14
  • 15. Nest 2-col layout in 2-col layout 15
  • 17. Determining nested widths width of column you want to match ÷ width of parent column = width of nested column 17
  • 18. Determining nested widths width of column you want to match ÷ width of parent column = width of nested column target ÷ context = result 18
  • 19. Determining nested widths width of column you want to match ÷ width of parent column = width of nested column target ÷ context = result 20 ÷ 80 = .25 which means 25% 19
  • 21. What about fluid grids? 21
  • 22. Width of this nested block? 22
  • 23. Well that's not right… 23
  • 24. To the laboratory! width of column you want to match ÷ width of parent column = width of nested column target ÷ context = result 25 ÷ 62.5 = .4 which means 40% 24
  • 26. ? widths spacing between and in fluid columns 26
  • 27. Leave a gap via widths 27
  • 28. Declaring fluid margin/padding • Adjust widths so everything adds to 100% • For IE 6/7, make it 99%: avoids problems due to rounding % to px • Nesting affects margin/padding values too • Use target÷context formula to match outer spacing with inner spacing 28
  • 29. Using box-sizing • Makes px & em margin/padding on fluid layout easy • Standard box model • box-sizing: content-box • Padding & border added on to width/height • New box model • box-sizing: border-box • Padding & border subtracted from width/height 29
  • 30. Fluid grid, fixed-width spacing .column { float: left; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 0 20px; Subtracted } from width in border-box box model 30
  • 31. Use border as faux margin .column { float: left; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 0 20px; border-left: 10px solid rgba(0,0,0,0); -moz-background-clip: padding-box; -webkit-background-clip: padding-box; background-clip: padding-box; } Prevents background from displaying under border 31
  • 32. Negate “margin” at start of row .column { float: left; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 0 20px; border-left: 10px solid rgba(0,0,0,0); -moz-background-clip: padding-box; -webkit-background-clip: padding-box; background-clip: padding-box; } .row { margin-left: -10px; Removes gap to } left of first column 32
  • 33. Fix box-sizing in IE 7 and 6 • Feed different dimensions based on content-box-model, or • Use Christian Schaefer's box-sizing polyfill https://github.com/Schepp/box-sizing-polyfill .column { box-sizing: border-box; *behavior: url(boxsizing.htc); } 33
  • 35. ? fluid hybrid one+ column flexible, one+ not 35
  • 36. Hybrid layout options • Easy: sidebars first in HTML • Float sidebars, main content moves up between floats • But usually not option in responsive design • Tricky: main content first in HTML • Need to float it, but with what width? • One solution: negative margins 36
  • 38. Add wrapper with padding #content-wrapper { padding-right: 290px; } 38
  • 39. Lay out main content div #content-main { float: left; width: 100%; } 39
  • 40. Float sidebar #content-secondary { float: right; width: 250px; } 40
  • 41. A positive right margin 150px 41
  • 42. A negative right margin -150px 42
  • 43. Pull sidebar into gap #content-secondary { float: right; width: 250px; margin-right: -290px; Matches } wrapper’s right padding, just negative 43
  • 44. Success! 44
  • 45. To make sidebar show in IE 6 #content-wrapper { zoom: 1; Adds hasLayout } #content-main, #content-secondary { display: inline; Hell if I know, } it just works 45
  • 46. 3-column hybrid layout • Nest one 2-column layout inside another • Components of each layout: 1. Wrapper with padding on one side 2. Fixed-width sidebar • Same width as padding (or smaller) • Floated same direction as padding • Negative margin matching padding on same side 3. Fluid column • Floated opposite direction • Width 100% 46
  • 47. ? fluid layout media queries feed different styles based on viewport size 47
  • 48. Choosing default styles • Start "mobile," layer on wider styles? • Start "desktop," layer on narrower styles? • Start somewhere in between, layer on both? • Learn full pros/cons: www.zomigi.com/blog/essential-considerations- crafting-quality-media-queries 48
  • 50. Wide-screen media query /*all the other styles up here*/ @media screen and (min-width: 1200px) { /*styles for larger screens in here*/ } 50
  • 51. 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%; } } 51
  • 52. Style nav as vertical menu @media screen and (min-width: 1200px) { ... #nav-main li { float: none; Stack links margin: 0; } #nav-main a { -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; Less tab-like } } 52
  • 54. Small-screen media query /*all the other styles up here*/ @media screen and (max-width: 760px) { /*styles for smaller screens in here*/ } 54
  • 55. Things to fix too few words per line, so make all one column each too narrow, so stack instead and put pic on left 55
  • 57. Mobile media query /*all the other styles up here*/ @media screen and (max-width: 550px) { /*styles for tiny screens in here*/ } 57
  • 58. Non-overlapping version @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*/ } 58
  • 59. Changing to single column @media screen and (max-width: 550px) { #content-main, #content-secondary, #about, #credits { float: none; width: 100%; } } 59
  • 60. 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); } } 60
  • 62. Viewport meta tag Forces mobile devices to scale viewport to actual device width <meta name="viewport" content="width=device-width"> 62
  • 63. Fix iOS zoom problems <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="ios-orientationchange-fix.js"> • Add initial-scale=1 to make page reflow when you switch to landscape • Add script to fix over-zoom bug that crops right side of page when you switch • See http://filamentgroup.com/lab/a_fix_for_ the_ios_orientationchange_zoom_bug/ 63
  • 64. Double-up inside the CSS Add @viewport rule, upcoming standard, inside style sheet: @-moz-viewport{ width:device-width } @-ms-viewport{ width:device-width } @-o-viewport{ width:device-width } @-webkit-viewport{ width:device-width } @viewport{ width:device-width } 64
  • 65. conditional comments or JavaScript to deal with IE 8 and earlier 65
  • 66. 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 66
  • 67. Conditional comment when desktop styles are default Feed IE Mobile 7 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 67
  • 68. Conditional comment when mobile styles are default Feed older IE media query sheet, hide from IE Mobile 7: <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/ 68
  • 69. 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-old-IE browsers using conditional comments: <!--[if (lt IE 9)&(!IEMobile 7)]> <script src="respond.min.js"></script> <![endif]--> 69
  • 71. Learn more Download slides and get links at http://bit.ly/rwdlayout Zoe Mickley Gillenwater @zomigi design@zomigi.com zomigi.com | stunningcss3.com | flexiblewebbook.com Photo credits: “023 Tape measure 006” by Steve James (http://www.flickr.com/photos/steeljam/3350481764/) “Phone Booths” by Kristin Nador (http://www.flickr.com/photos/kristinnador/7744274382/) “Reese’s Pieces” by Dave Brown (http://www.flickr.com/photos/taids/2143865543/) “Frank on the main wall” by Justin Johnson (http://www.flickr.com/photos/justinjohnsen/4512815628/) 71