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

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

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

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

Viewports. Peter-Paul Koch DevReach, 13 November 2017

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

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

Responsive Design. Responsive Design Approach. Technique for building webpages

The plural of Chromium is Chromia. Peter-Paul Koch NLHTML5 Rotterdam, 19 February 2015

Contents FORMAT 3. Specifications STATIC ADVERTISING 4. Interstitial HTML5 ADVERTISING 5-12

Web Design and Implementation

CS7026 Media Queries. Different Screen Size Different Design

Chapter 7 BMIS335 Web Design & Development

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

The plural of Chromium is Chromia. Peter-Paul Koch Mobilism, 27 March 2015

ORB Education Quality Teaching Resources

How to deploy for multiple screens

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

HTML and CSS a further introduction

Web Site Design and Development Lecture 13

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

Web App Vs Web Site. Some tricks of the trade. Laurent Technical Director, BlackBerry Web Platform

Building Responsive Layouts

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

The mobile browser world. Peter-Paul Koch Front-end Day workshop, 26 April 2011

Introduction to WEB PROGRAMMING

Mobile & More: Preparing for the Latest Design Trends

Perfect Student Midterm Exam March 20, 2007 Student ID: 9999 Exam: 7434 CS-081/Vickery Page 1 of 5

Styles, Style Sheets, the Box Model and Liquid Layout

Hell is other browsers - Sartre. The touch events. Peter-Paul Koch (ppk) WebExpo, 24 September 2010

door to my garden Simple CSS resulting in impressive, sophisticated visual effects

CISC 1600 Lecture 1.4 Design, part 2. Topics: Accessibility Responsive web design Example design review

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

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

International Conference KNOWLEDGE-BASED ORGANIZATION Vol. XXIII No RESPONSIVE WEB DESIGN TECHNIQUES. Luminita GIURGIU, Ilie GLIGOREA

Designing for the Mobile Web

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

FLOATING AND POSITIONING

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

The Importance of the CSS Box Model

1.7 Limit of a Function

The Economist Apps. Advertising specs

Positioning in CSS: There are 5 different ways we can set our position:

The Benefits of CSS. Less work: Change look of the whole site with one edit

Header. Article. Footer

Class 3 Page 1. Using DW tools to learn CSS. Intro to Web Design using Dreamweaver (VBUS 010) Instructor: Robert Lee

Introduction to Computer Science Web Development

Responsive Web Design Discover, Consider, Decide

Responsive Web Design (RWD)

B r o w s e r s u p p o r t

Eng 110, Spring Week 03 Lab02- Dreamwaver Session

Advertising specifications. Version 1.1

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

HTML Organizing Page Content

QCon - Mobile Maps HTML5 Team Andrea

CSS worksheet. JMC 105 Drake University

CIT BY: HEIDI SPACKMAN

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

Mobile Applications 2013/2014

BORDER IMAGES THE BACKGROUND IMAGE PROPERTIES. Learning Web Design, 5e

Microsoft Expression Web Quickstart Guide

Student, Perfect CS-081 Final Exam May 21, 2010 Student ID: 9999 Exam ID: 3122 Page 1 of 6 Instructions:

Hands on with EPUB (workshop)

HTML Organizing Page Content

Graduating to Grid. An Event Apart Orlando

Block & Inline Elements

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

Designing the Home Page and Creating Additional Pages

CS7026 Media Queries II. Different Screen Size Different Design

epromo Guidelines DUE DATES NOT ALLOWED PLAIN TEXT VERSION

RC Justified Gallery User guide for version 3.2.X. Last modified: 06/09/2016

Assignments (4) Assessment as per Schedule (2)

Create First Web Page With Bootstrap

What do we mean by layouts?

How to lay out a web page with CSS

Manually Zoom Out Mac Screen Size

Table of contents. Sliding Panels DMXzone.com

Week 8 Google Maps. This week you ll learn how to embed a Google Map into a web page and add custom markers with custom labels.

Chapter 8: Using Toolbars

How mobile is changing and what publishers need to do about it

New frontier of responsive & device-friendly web sites

Website Design (Weekday) By Alabian Solutions Ltd , 2016

11/5/16 WEB DESIGN. Branding Fall 2016

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

What if we want the child elements to calculate the offset from the boundaries of the document? CSS LAYOUT. The position Property.

INFS 2150 Introduction to Web Development

Welcome. Web Authoring: HTML - Advanced Topics & Photo Optimisation (Level 3) Richard Hey & Barny Baggs

INFS 2150 Introduction to Web Development

Brunch & Learn: Design Best Practices for Desktop, Mobile, Tablet & Beyond

COMP519 Web Programming Lecture 8: Cascading Style Sheets: Part 4 Handouts

CREATIVE & TECHNICAL SPECIFICATIONS

The World In. Advertising specs

[AVWSQ-ADWCS6]: WSQ ICDL Adobe Dreamweaver CS6

CS7026 CSS3. CSS3 Graphics Effects

Using Dreamweaver CS6

Write a Touch-friendly HTML5 App. Hongbo Min, Intel Junmin Zhu, Intel Yongsheng Zhu, Intel

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

16A CSS LAYOUT WITH FLEXBOX

ITEC447 Web Projects CHAPTER 10 FLASH & SILVERLIGHT 1

Fish Eye Menu DMXzone.com Fish Eye Menu Manual

Website Design (Weekend) By Alabian Solutions Ltd , 2016

Transcription:

A pixel is not a pixel Peter-Paul Koch http://quirksmode.org http://twitter.com/ppk SF HTML5, 6 April 2012

Example site http://mobilism.nl/2012/ A proper responsive site that you can use on any device For most of the presentation I m going to pretend it s not mobile-optimised

A pixel is not a pixel Three kinds of pixels Two viewports Zooming How to access all this with JavaScript Media queries width and device-width Meta viewport

Pixels

A pixel is not a pixel CSS pixels Density-independent pixels Device pixels

CSS pixels CSS pixels are the ones we use in declarations such as width: 190px or padding-left: 20px They are what we want Their size may be increased or decreased, though

Device pixels Device pixels are the physical pixels on the device They have a fixed size that depends on the device

Device pixels

Device pixels <meta name= viewport content= width = device-width > What is the device width? The number of device pixels So on the iphone, your site is restricted to 320px

Device pixels But... Devices get higher and higher pixel densities In theory this would mean that the meta viewport width also goes up But that would break sites

Device pixels

Density-independent pixels

Density-independent pixels Thus device vendors created densityindependent pixels (dips) They are another abstraction layer The number of dips is equal to the number of CSS pixels that is optimal for viewing a website on the device at 100% zoom For the iphone that s 320px

Density-independent pixels <meta name= viewport content= width = device-width > What is the device width? The number of dips So on the iphone, your site is still restricted to 320px even on a Retina display

What do we need? CSS pixels Density-independent pixels Device pixels

What do we need? CSS pixels Density-independent pixels Device pixels

What kind of pixels? If a certain JavaScript property is expressed in pixels always ask yourself what kind of pixels. Usually it s CSS pixels, especially for anything related to CSS Sometimes it s device pixels or dips, for anything related to screen size

Viewports

Viewports The viewport is the total amount of space available for CSS layouts On the desktop it s equal to the browser window The <html> element has an implicit width: 100% and spans the entire viewport

Viewports On mobile it s quite a bit more complicated If the (narrow) browser window were to be the viewport, many sites would be squeezed to death And mobile browsers must render all sites correctly, even if they haven t been mobileoptimized

Viewports That s why the mobile browser vendors have split the viewport into two: The layout viewport, the viewport that CSS declarations such as padding-left: 34% use,

Viewports That s why the mobile browser vendors have split the viewport into two: The layout viewport, the viewport that CSS declarations such as padding-left: 34% use, and the visual viewport, which is the part of the page the user is currently seeing Both are measured in CSS pixels

Viewports Initially most browsers make the visual viewport equal to the layout viewport by zooming the page out as much as possible

Viewports Initially most browsers make the visual viewport equal to the layout viewport by zooming the page out as much as possible Although the page is unreadable, the user can at least decide which part he d like to concentrate on and zoom in on that part

Zooming

Zooming Zooming on desktop and mobile are totally different On desktop the viewport is narrowed, which causes elements with padding-left: 34% to be recalculated (though they should still take up the same ratio) and elements with a width: 190px to become relatively wider

Zooming On mobile the visual viewport is decreased, so that the user sees less of the complete site

Zooming On the desktop the viewport becomes less wide and the CSS pixels become larger. The same amount of device pixels now contain less CSS pixels, after all.

Zooming On mobile the visual viewport becomes less wide, but the layout viewport remains static. Thus CSS declarations are not recomputed. The visual viewport now contains less CSS pixels.

JavaScript properties

JavaScript properties screen.width and screen.height The width and height of the screen In device pixels (or dips) Totally useless. Don t bother reading it out

JavaScript properties document.documentelement.clientwidth and document.documentelement.clientheight The width and height of the layout viewport In CSS pixels Useful, though mostly because of media queries

JavaScript properties window.innerwidth and window.innerheight The width and height of the visual viewport In CSS pixels Extremely important. It tells you how much the user is currently seeing

JavaScript properties document.documentelement.offsetwidth and document.documentelement.offsetheight The width and height of the <html> element In CSS pixels Very occasionally useful

JavaScript properties window.pagexoffset and window.pageyoffset The current scrolling offset In CSS pixels Useful. Works just as on desktop

JavaScript properties System pioneered by Nokia and BlackBerry Picked up by Apple Android supports it only from 3 on IE9 on Windows Phone does not support it But otherwise browser compatibility is quite decent

JavaScript properties document.documentelement.clientwidth / window.innerwidth This gives the current zoom level You re not interested in the zoom level, though You want to know how much the user is currently seeing The visual viewport, in other words

Media queries

Media queries There are two important media queries: width device-width width is the one you want

Media queries device-width gives the width of the device screen in device pixels Equal to screen.width

Media queries width gives the width of the viewport in CSS pixels (There are a few zooming problems on desktop, though) Equal to document.documentelement.clientwidth

Media queries device-width gives the width of the device screen in device pixels or dips Equal to screen.width On mobile the screen is far smaller than on desktop, but that doesn t matter

Media queries width gives the width of the viewport in CSS pixels Equal to document.documentelement.clientwidth On mobile this means the layout viewport

Media queries width is the media query you want but at first sight it seems to be totally useless on mobile Usually we don t care about the width of the layout viewport We need to treat one more element, though.

Meta viewport

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

Meta viewport @viewport { width: device-width; } Only Opera for now

Meta viewport <meta name= viewport content= width = device-width > The meta viewport tag tells the browser to set the size of the layout viewport You can give a pixel value or device-width, which means the screen size in dips

Meta viewport <meta name= viewport content= width = device-width > There is little reason to use other values than device-width And because you tell the layout viewport to become as wide as the device the width media query now contains useful data

Media queries In theory the device-width and width media queries would now return the same values but only when the zoom level is 100% This is a frighteningly complicated area Don t go there Use width

Mobile versions So the trick for creating a mobile version of a site is using <meta name= viewport content= width=device-width /> in combination with width media queries You probably already knew that but now you also understand why

Thank you I ll put these slides online Questions? Peter-Paul Koch http://quirksmode.org http://twitter.com/ppk SF HTML5, 6 April 2012