CS7026 Media Queries. Different Screen Size Different Design

Similar documents
Media-Specific Styles

INTRODUCTION TO HTML5! CSS Styles!

Media Types & Media Features

CIT BY: HEIDI SPACKMAN

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

Responsive Design. Responsive Design Approach. Technique for building webpages

Designing for the Mobile Web

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

Introduction to Cascading Style Sheet (CSS)

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

Creating and Building Websites

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

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

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

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

YouTube Break.

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

Chapter 7 BMIS335 Web Design & Development

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

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

CSS: Responsive Design, CSS3 and Fallbacks

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

Building Responsive Layouts

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

Viewports. Peter-Paul Koch DevReach, 13 November 2017

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]

Scripting for Multimedia LECTURE 5: INTRODUCING CSS3

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

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

Web Site Design and Development Lecture 13

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

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

Internet Programming 1 ITG 212 / A

HTML5:n mahdollisuudet ja rajoitukset e-julkaisun lukemisessa ja tuottamisessa

New frontier of responsive & device-friendly web sites

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

Mobile Applications 2013/2014

Reading 2.2 Cascading Style Sheets

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

Web Site Design Small Screen Design Responsive Design R.I.T. S. Ludi/R. Kuehl p. 1 R I T. Software Engineering

CSS: Cascading Style Sheets

CSS: The Basics CISC 282 September 20, 2014

Responsive Web Design (RWD)

Styles, Style Sheets, the Box Model and Liquid Layout

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

CS7026 CSS3. CSS3 Graphics Effects

Developing Web Applications for Smartphones with IBM WebSphere Portlet Factory 7.0

Assignments (4) Assessment as per Schedule (2)

Introduction to Computer Science Web Development

Understanding Browsers

Manually Zoom Out Mac Screen Size

CSS. CSS is the style language for web pages. CSS stylesheets example

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

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

Responsive Design and Mobile Patterns

Flexible and LEAN Ads

CSS means Cascading Style Sheets. It is used to style HTML documents.

The University of Hawaii at Manoa Library Webpage Content/Design/Style Guidelines General Site Design... 2

User Help

User Interfaces for Web Sites and Mobile Devices. System and Networks

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

Development Training. For Developer. 4 th May, AOT Intranet Web Portal

Navigation. Websites need a formalized system of links to allow users to navigate the site

CSC309 Programming on the Web week 3: css, rwd

Comm 244 Week 3. Navigation. Navigation. Websites need a formalized system of links to allow users to navigate the site

HTML/XML. HTML Continued Introduction to CSS

Tutorial 4: Creating Special Effects with CSS

CSS Data Types. One of Those Things You Have To Know

Iphone Usb Tethering Windows 7 No Internet. Access >>>CLICK HERE<<<


Media Stylesheets and Navigation with CSS goodness. Webpage Design

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

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

CHAPTER 4: MICROSOFT OFFICE: EXCEL 2010

Graduating to Grid. An Event Apart Orlando

How to deploy for multiple screens

Session 3.1 Objectives Review the history and concepts of CSS Explore inline styles, embedded styles, and external style sheets Understand style

CSS - Cascading Style Sheets

CS7026 Media Queries II. Different Screen Size Different Design

Lesson 1 using Dreamweaver CS3. To get started on your web page select the link below and copy (Save Picture As) the images to your image folder.

Safari Web Content Guide

Excel Level Three. You can also go the Format, Column, Width menu to enter the new width of the column.

Lab 1: Introducing HTML5 and CSS3

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

The Marketer s Guide to. Responsive Design

CSSSTYLE: Stylish Output with ODS and SAS 9.2 Cynthia L. Zender, SAS Institute Inc., Cary, NC

epromo Guidelines DUE DATES NOT ALLOWED PLAIN TEXT VERSION

Library in Your Pocket

Responsive Web Design. Sheri German, Instructor Montgomery College

The purpose of Veco Mobile is to give remote workers, such as negotiators and property management/maintenance staff real-time access to Veco data.

Standard Design Reference

Hypertext Markup Language, or HTML, is a markup

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

Building Responsive Websites

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

Creating Layouts Using CSS. Lesson 9

Status: SEO Tests. Title. Title Length. Title Relevancy. Description. Description Length. Description Relevancy. Keywords.

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

Transcription:

CS7026 Media Queries Different Screen Size Different Design

Introduction Users no longer view web content only on traditional desktop systems, but are increasingly using smartphones, tablets, and other devices with a wide range of dimensions. The challenge for web designers is to ensure that their websites look good not only on a big screen, but also on a tiny phone and everything in between. Media queries are an excellent way to deliver different styles to different devices, providing the best experience for each type of user. 2

Introduction Media queries are part of the CSS3 specification. They expand the role of the media attribute that controls how your styles are applied. E.g., it's been common practice for years to use a separate style sheet for printing web pages by specifying media= print. Media queries take this idea to the next level by allowing designers to target styles based on a number of device properties, such as screen width, orientation, and so on. 3

Introduction So CSS Media Queries are a feature in CSS3 which allows you to specify when certain CSS rules should be applied. This allows you to apply a special CSS for mobile, or adjust a layout for print. 4

The basic syntax looks like this: /* normal style */ #header-image { background-repeat: no-repeat; background-image:url('image.gif'); } /* show a larger image when you're on a big screen */ @media screen and (min-width: 1200px) { #header-image { background-image:url('large-image.gif'); } } /* remove header image when printing. */ @media print { #header-image { display: none; } } 5

But can also be called like this: <link rel='stylesheet' media='all' href='normal.css' /> <link rel='stylesheet' media='print' href='print.css' /> <link rel='stylesheet' media='screen and (min-width: 701px)' href='medium.css' /> The advantage of this method is that only the valid CSS is downloaded; so print.css is only downloaded when printing (or using print preview). 6

Media Queries Combining media queries can be done by combining them with an comma. The query below is to target devices with an device-ratio of 1.5. The first element is for webkit, the second is for all other browsers (1.5 * 96). @media screen and (-webkit-device-pixel-ratio: 1.5), screen and (resolution: 144dpi) 7

When a pixel is not a pixel (an aside) The device pixel ratio (also called CSS Pixel Ratio) is what determines how a device's screen resolution is interpreted by the CSS. The reason it was created is because as phones screens get higher resolutions, if every device still had a CSS pixel ratio of 1 then webpages would render too small to see. A typical full screen desktop monitor is a 24" monitor at 1920x1080. Imagine if that monitor was shrunk down to < 5" but had the same resolution. Viewing things on the screen would be impossible because they would be so small. 8

When a pixel is not a pixel (an aside) CSS interprets a device's resolution by the formula: device_resolution/css_pixel_ratio. For example: Samsung Galaxy S III Actual resolution: 720 x 1280 CSS Pixel Ratio: 2 Interpreted resolution: 720/2 x 1280/2 = 360 x 640 9

When a pixel is not a pixel (an aside) When viewing a web page, the CSS will think the device has a 360x640 resolution screen and Media Queries will respond as if the screen is 360x640. But the rendered elements on the screen will be twice as sharp as an actual 360x640 screen. So the number describes the ratio of how much "real" pixels (physical pixels of the screen) are used to display one "virtual" pixel (size set in CSS). 10

When a pixel is not a pixel (an aside) Some other examples: Samsung Galaxy S4 Actual Resolution: 1080 x 1920 CSS Pixel Ratio: 3 Interpreted Resolution: 1080/3 x 1920/3 = 360 x 640 iphone 5s Actual Resolution: 640 x 1136 CSS Pixel Ratio: 2 Interpreted Resolution: 640/2 x 1136/2 = 320 x 568 11

Back to Media Queries Because it's cascading all non-overwritten rules remain valid; e.g. the background remains no-repeat. Using this syntax you can do a number of things; Tweak that font so it really fits on that old iphone, Remove menus and fluff from Print pages Create a full responsive site, by creating 'breakpoints' where the page should get a different design. 12

Media Queries For example: #block1, #block2 { float: left; width: 100%; } @media (min-width: 1000px) { #block1, #block2 { width: 50%; } } This example shows the 2 blocks on big screens next to each other, while on small screens they will be displayed below each other. 13

Support Media queries are supported in Internet Explorer (IE) 9+, Firefox 3.5+, Safari 3+, Opera 7+, as well as on most modern smartphones and other screen-based devices. 14

Available media types: all: All devices listen to this braille: Used for braille tactile feedback devices. embossed: Used for paged braille printers. handheld: Used for handheld devices (Smartphones and tablets do NOT listen to this!). print: Used for paged material and for documents viewed on screen in print preview mode. 15

Available media types: projection: Used for projected presentations, for example projectors. screen: Used primarily for colour computer screens and smartphones. speech: Used for speech synthesizers.. tty: Used for media using a fixed-pitch character grid (such as teletypes, terminals, or portable devices with limited display capabilities). tv: Used for television-type devices (low resolution, colour, limited-scrollability screens, sound available). 16

Available media types: Of course browsers don't behave the way we expect to do. Most important; the handheld media type is not used by smartphones and tablets. Smartphones respond to screen. So in effect, the handheld media type is quite useless. The TV media type apparently works with the Wii browser, powered by Opera. But that s about it. All other smart TVs seem to have gone for screen as well. 17

Media Features for setting conditions in media queries Feature Value Min/Max Description width Length Yes Width of display area height Length Yes Height of display area device-width Length Yes Width of device device-height Length Yes Height of device orientation portrait or landscape No aspect-ratio Ratio (w/h) Yes Orientation of device Ratio of width to height, expressed as two integers separated by a slash (e.g., 16/9) 18

Media Features for setting conditions in media queries Feature Value Min/Max Description deviceaspectratio Ratio (w/h) Yes Ratio of device-width to device-height color Integer Yes colorindex Integer Yes monochrome Integer Yes Number of bits per colour component (if not colour, the value is 0) Number of entries in the output device's colour lookup table Number of bits per pixel in the monochrome frame buffer (if not monochrome, the value is 0) 19

Media Features for setting conditions in media queries Feature Value Min/Max Description resolution Resolution Yes Density of pixels of output device, express as integer followed by dpi (dots per inch) or dpcm (dots per centimeter) scan progressive or interlace No Scanning process used by TV devices grid 0 or 1 No If set to 1, the device is gridbased, such as a teletype terminal or phone display with only one fixed font (all other devices are 0) 20

Media Features The first five features (width, height, devicewidth, device-height, and orientation ) are the most useful. You can prefix most features with min- and max- to indicate minimum and maximum values, such as minwidth and max-width. 21

width, device-width, and viewport Perhaps one of the most confusing aspects of media queries is the difference between width and height and the equivalent values prefixed by device-. In the case of desktop and laptop computers, the difference is easy to understand: width and height refer to the size of the browser viewport, whereas device-width and deviceheight refer to the dimensions of the monitor. Not everybody runs his or her browser full-screen, so width and height are the measurements that you need to use. 22

width, device-width, and viewport Mobile browsers fill the available screen, so you might expect width and device-width to be the same. Unfortunately, that's not always the case. Most smartphones, including Android, iphone, and Windows Phone 7, set width to a nominal viewport approximately 1,000 pixels wide (in an iphone and ipod touch, it's 980 pixels, Windows Phone 7 uses 1024 pixels). 23

width, device-width, and viewport Even though the style sheet attached to the page may use media queries to serve different styles depending on the values of min-width and max-width, the ipod touch ignores the styles and displays the desktop version because the viewport is considered to be 980 pixels wide. To confuse matters even further, the iphone, ipod touch, and ipad don't take orientation into account when calculating width, whereas other devices do. 24

width, device-width, and viewport Thankfully, there's a simple solution to this confusion. Apple devised a new <meta> tag, which has been widely adopted by other mobile device manufacturers and has been incorporated into the specification likely to be approved by the W3C. Add the following line to the <head> of each web page: <meta name="viewport" content="width=device-width, initial-scale=1"> 25

width, device-width, and viewport This tells mobile devices to treat the viewport as being the same width as the physical width of the device. What's more, it tells the iphone, ipod touch, and ipad to take orientation into account when calculating width. As a result, you can use width in media queries safe in the knowledge that it means what you think it does. 26

How to Write Media Queries A Closer Look To add a media query to the media attribute, you set one or more conditions using the available media features. You specify the value for a media feature after a colon in the same way as for a CSS property. Each condition is wrapped in parentheses and added to the media declaration using the keyword and. media="screen and (min-width: 401px) and (max-width: 600px)" 27

How to Write Media Queries Media queries are Boolean: they will either be true or false. If the entire statement is true, the style sheet is applied. If false, it will be ignored. So when using the query, all parts must be true for the style sheet to be applied. In other words, it will apply only to screens between 401 and 600 pixels wide. 28

How to Write Media Queries Some media features, such as color, monochrome, and grid, can be used as conditions without specifying a value. For example, the following targets all colour visual displays: media="screen and (color)" 29

Specifying Alternatives There is no or keyword to specify alternative media features. Instead, you list alternatives as a comma-separated list like this: media="screen and (min-width: 769px), print and (min-width: 6in)" This applies styles to screens wider than 769 pixels or print devices using paper at least 6 inches wide. 30

Specifying Negative Conditions To specify a negative condition, you can precede the media declaration with the keyword not like this: media="not screen and (monochrome) You can't use not in front of an individual condition. The keyword must come at the beginning of the declaration, and it negates the whole declaration. So, the preceding example applies to all devices except monochrome screens. 31

Hiding media queries from older browsers The media queries specification also provides the keyword only, which is intended to hide media queries from older browsers. Like not, the keyword must come at the beginning of the declaration. For example: media="only screen and (min-width: 401px) and (max-width: 600px)" 32

Hiding media queries from older browsers Browsers that don't recognize media queries expect a comma-separated list of media types, and the specification says they should truncate each value immediately before the first non-alphanumeric character that isn't a hyphen. So, an old browser should interpret the preceding example as this: media="only" Because there is no such media type as only, the style sheet is ignored. 33

Hiding media queries from older browsers Similarly, an old browser should interpret the following as media="screen" : media="screen and (min-width: 401px) and (max-width: 600px)" In other words, it should apply the style rules to all screen devices, even though it doesn't know what the media queries mean. 34

Hiding media queries from older browsers Unfortunately, IE 6 8 failed to implement the specification correctly - instead of applying the styles to all screen devices, it ignores the style sheet altogether. In spite of this behaviour, it's still recommended to prefix media queries with only if you want to hide the styles from other, less common browsers. 35

Dealing with older versions of Internet Explorer The lack of support for media queries in IE 6 through IE 8 is not a problem. Simply create a basic set of styles that are served to all browsers without using media queries, and use the media queries to provide an enhanced experience for visitors using more advanced browsers. 36

Dealing with older versions of Internet Explorer Alternatively, use an Internet Explorer conditional comment to serve a special set of rules to older versions of IE like this: <!--[if lt IE 9 &!IEMobile]> <link href="iestyles.css" rel="stylesheet" type="text/css"> <![endif]--> 37

Using media queries with @import and @media In addition to using media queries in <link> tags when attaching an external style sheet, you can use them with @import and @media. The basic syntax is the same. E.g., the following imports a style sheet and applies the styles to devices with a screen that's no wider than 400 pixels: @import url("phone.css") only screen and (max-width:400px); 38

Using media queries with @import and @media Media queries can also be used within a style sheet like this: @media only screen and (max-width:400px) { #navbar { float: none; width: 400px; } } 39