Building Responsive Layouts

Similar documents
CSS3, Media Queries, & Responsive Design. May 23, 2012 STC Summit Zoe Mickley

CSS3: Using media queries to improve the web site experience. November 19, 2011 indieconf Zoe Mickley

Designing with CSS3 Effectively & Efficiently. October 2010 Adobe MAX Zoe Mickley

Introduction to Computer Science Web Development

Building Page Layouts

CS7026 Media Queries II. Different Screen Size Different Design

Chapter 7 BMIS335 Web Design & Development

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

Responsive web design (RWD) CSS3 Media queries. Mobile vs desktop web sites. Web Development 1 CS1115/CS5002

CS7026 Media Queries. Different Screen Size Different Design

CSS: Layout Part 2. clear. CSS for layout and formatting: clear

Viewports. Peter-Paul Koch CSS Day, 4 June 2014

Cascading Style Sheets for layout II CS7026

Enhancing Responsiveness. Flexbox WITH. SmashingConf March Zoe Mickley

Graduating to Grid. An Event Apart Orlando

Front-End UI: Bootstrap

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

Web Site Design and Development Lecture 13

Responsive Design. Responsive design is it important? But typical is not enough. Some typical screen sizes

HTML Organizing Page Content

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) More on Relative Linking. Learning Objectives (2 of 2)

Responsive Web Design (RWD)

CSS: Responsive Design, CSS3 and Fallbacks

A pixel is not a pixel. Peter-Paul Koch BlackBerry Jam, 6 February 2012

HTML and CSS a further introduction

Table Basics. The structure of an table

How to deploy for multiple screens

CSC309 Programming on the Web week 3: css, rwd

Cascading Style Sheets Level 2

PUTTING FLEXBOX INTO PRACTICE. Blend Conference September Zoe Mickley

Zen Garden. CSS Zen Garden

Styles, Style Sheets, the Box Model and Liquid Layout

Page Layout. 4.1 Styling Page Sections 4.2 Introduction to Layout 4.3 Floating Elements 4.4 Sizing and Positioning

Responsive Web Design and Bootstrap MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

A pixel is not a pixel. Peter-Paul Koch MoBeers, 10 April 2012

Create a three column layout using CSS, divs and floating

Website Design (Weekend) By Alabian Solutions Ltd , 2016

CS7026 CSS3. CSS3 Graphics Effects

HTML5 and Mobile: New Markup & Styles for the Mobile Web. Jason Clark Head of Digital Access & Web Services Montana State University Libraries

Frontend guide. Everything you need to know about HTML, CSS, JavaScript and DOM. Dejan V Čančarević

Responsive Design. Responsive Design Approach. Technique for building webpages

HTML Organizing Page Content

Programming web design MICHAEL BERNSTEIN CS 247

TAG STYLE SELECTORS. div Think of this as a box that contains things, such as text or images. It can also just be a

Responsive Web Design. From: Ethan Marcotte - Responsive Web Design 2011

Website Design (Weekday) By Alabian Solutions Ltd , 2016

Responsive Web Design. Sheri German, Instructor Montgomery College

Client-Side Web Technologies. CSS Part II

Web Design and Implementation

AGENDA. :: Add Meta Tag for Viewport (inside of head element): :: Add Script that renders HTML5 elements for older versions of Internet Explorer

Adaptations by PVII responsive and then creates your page instantly Al Sparber & Gerry Jacobsen PVII

HTML5 and CSS3: New Markup & Styles for the Emerging Web. Jason Clark Head of Digital Access & Web Services Montana State University Library

FLOATING AND POSITIONING

Viewports. Peter-Paul Koch DevReach, 13 November 2017

CSS THE M\SS1NG MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLr Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

Assignments (4) Assessment as per Schedule (2)

A pixel is not a pixel. Peter-Paul Koch SF HTML5, 6 April 2012

Introduction to HTML & CSS. Instructor: Beck Johnson Week 2

What is the Box Model?

Friday, January 18, 13. : Now & in the Future

CSC309 Winter Lecture 2. Larry Zhang

AGENDA. EMBEDDING FONTS [ Font Files & CSS font-family ] :: Online Font Converter :: ADD font-family css code to style.css

CSS Cascading Style Sheets

TODAY S AGENDA. An introduction for Libraries UW-SLIS CES Webinar April 6, 2015 What is Responsive Web Design? Definition & History

CSS.

BA. (Hons) Graphics Design

Media Types & Media Features

More CSS goodness with CSS3. Webpage Design

Media-Specific Styles

CSS for Designers. Capabilities to Know & Pitfalls to Avoid. R. Scott Granneman. Jans Carton

Using CSS for page layout

Web Design & Dev. Combo. By Alabian Solutions Ltd , 2016

CSS: The Basics CISC 282 September 20, 2014

Here are some links to get you started in learning more about CSS3 media queries and responsive web design:

Page Layout Using Tables

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

CSS Layout Part I. Web Development

Advanced Dreamweaver CS6

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

Class 9 / Instructor: Ira Epstein

Introduction to HTML & CSS. Instructor: Beck Johnson Week 5

How to lay out a web page with CSS

Web Site Design and Development Lecture 9. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

Designing the Home Page and Creating Additional Pages

YouTube Break.

IBM Forms V8.0 Custom Themes IBM Corporation


Want to read more? You can buy this book at oreilly.com in print and ebook format. Buy 2 books, get the 3rd FREE!

Responsive Design for Web Applications R.I.T. S. Ludi/R. Kuehl p. 1 R I T. Software Engineering

AGENDA :: MULTIMEDIA TOOLS :: CLASS NOTES. INSTALLING FONTS :: Download, Install, & Embed Your Fonts. LECTURE :: Responsive Web Design [RWD]

Lab 1: Introducing HTML5 and CSS3

CSS: Lists, Tables and the Box Model

IDM 221. Web Design I. IDM 221: Web Authoring I 1

Lab Introduction to Cascading Style Sheets

CSS: Cascading Style Sheets

COMSC-031 Web Site Development- Part 2

CSS Cascading Style Sheets

IMY 110 Theme 11 HTML Frames

Transcription:

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; } #content-main, #content-secondary { display: inline; } Adds haslayout 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-considerationscrafting-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; margin: 0; } #nav-main a { -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; } } Stack links 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

Narrowscreen 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-mobileoptimized-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 nonsupporting 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