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

Similar documents
Responsive Web Design (RWD)

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

Fixed-width. Liquid. Web Development 1 CS1115/CS5002. Types of layout. relative, fixed), CSS Flexbox layout or CSS Grid Layout

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

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 Approach. Technique for building webpages

Styles, Style Sheets, the Box Model and Liquid Layout

Zen Garden. CSS Zen Garden

Chapter 7 BMIS335 Web Design & Development

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

CSC309 Programming on the Web week 3: css, rwd

CSS Selectors. element selectors. .class selectors. #id selectors

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

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

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

Assignments (4) Assessment as per Schedule (2)

CS193X: Web Programming Fundamentals

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

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

Create a three column layout using CSS, divs and floating

FEWD START SCREENCAST!!!!

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

CS7026 Media Queries II. Different Screen Size Different Design

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

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar

16A CSS LAYOUT WITH FLEXBOX

CSS.

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

CSS often uses hyphens in CSS property names but JavaScript uses camel case, e.g. color: blue; p { <!DOCTYPE html> <meta charset="utf-8" /> <head>

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

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

Introduction to Computer Science Web Development

/* ========================================================================== PROJECT STYLES

CSS: The Basics CISC 282 September 20, 2014

CSC 121 Computers and Scientific Thinking

Lab 1: Introducing HTML5 and CSS3

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

Front-End UI: Bootstrap

FLOATING AND POSITIONING

CSC Website Design, Spring CSS Flexible Box

CSS worksheet. JMC 105 Drake University

WEBSITE PROJECT 2 PURPOSE: INSTRUCTIONS: REQUIREMENTS:

Page Layout Using Tables

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

Appendix D CSS Properties and Values

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

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

Building Responsive Layouts

Reading 2.2 Cascading Style Sheets

CIT BY: HEIDI SPACKMAN

HTML Organizing Page Content

Adding CSS to your HTML

When you complete this chapter, you will be able to:

Chapter 16: PAGE LAYOUT WITH CSS

Graduating to Grid. An Event Apart Orlando

HTML Organizing Page Content

Table Basics. The structure of an table

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

Guidelines for doing the short exercises

HTML and CSS a further introduction

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

Block & Inline Elements

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

McMaster Brand Standard for Websites

Project 1: Creating a Web Site from Scratch. Skills and Tools: Use Expression Web tools to create a Web site

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

Goldfish 4. Quick Start Tutorial

Module 2 (VII): CSS [Part 4]

HIERARCHICAL ORGANIZATION

Introducing CSS Flexbox Layout

YouTube Break.

Introduction to WEB PROGRAMMING

2. Write style rules for how you d like certain elements to look.

Taking Fireworks Template and Applying it to Dreamweaver

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

Programming web design MICHAEL BERNSTEIN CS 247

CSCU9B2: Web Tech Lecture 3

Media-Specific Styles

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

HTMLnotesS15.notebook. January 25, 2015

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

ORB Education Quality Teaching Resources

CSS Design and Layout Basic Exercise instructions. Today's exercises. Part 1: Arrange Page into Sections. Part 1, details (screenshot below)

Using CSS for page layout

Web Design and Implementation

ICT IGCSE Practical Revision Presentation Web Authoring

Enhancing Responsiveness. Flexbox WITH. SmashingConf March Zoe Mickley

Multimedia Systems and Technologies Lab class 6 HTML 5 + CSS 3

Chapter 3 Style Sheets: CSS

Cascading Style Sheets (CSS)

Cascading Style Sheet Quick Reference

Country Communication Pages

Web Design and Development ACS Chapter 12. Using Tables 11/23/2017 1

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Media Types & Media Features

CSS: Cascading Style Sheets

Transcription:

1 of 13 CS1115/CS5002 Web Development 1 Dr Derek Bridge School of Computer Science & Information Technology University College Cork Mobile vs desktop web sites A few organization have two web sites, one for 'desktop' and one for 'mobile', (with different URLs), e.g. https://en.wikipedia.org/wiki/napoleon https://en.m.wikipedia.org/wiki/napoleon Their server may even try to automatically decide which version to serve from headers in your HTTP request Responsive Web Design (RWD) is a relatively new, but widespread, alternative 2 of 13 Responsive web design (RWD) A flexible (liquid) layout, based on a grid Flexible image and media Media queries Least-capable-clients-first ('mobile-first') Progressive enhancement CSS3 Media queries color: white; background-color: black; @media screen and (min-width: 480px) { background-color: red; @media screen and (min-width: 768px) { background-color: blue; @media screen and (min-width: 1024px) { background-color: yellow; min-width refers to the viewport (browser window) This CSS says: Use a black background If the viewport is at least 480px, use a red background If the viewport is at least 768px, use a blue background If the viewport is at least 1024px, use a yellow background Question: Suppose the viewport is 1200px, then all the above are true. Why will the background be yellow?

3 of 13 CSS3 Media queries Simple media queries comprise the media type: screen, print and 8 more an expression: a media feature (e.g. min-width) and a value (e.g. 768px) in parentheses some CSS between curly braces A list of the media features that you can use The browser applies the enclosed CSS only if the query is true Media queries for RWD Use media queries to adapt to a range of devices: Adapt the overall layout, e.g. a single-column layout for narrower viewports one or more multi-column layouts for wider viewports Adapt individual components, e.g. vertically-stacked navigation menus versus horizontal ones headers containing logos above slogans versus logos next to slogans (Sometimes you don't need media queries to make components adaptive consider how adaptive flexboxes can be) 4 of 13 Least-capable-clients-first and progressive enhancement 1. Write nice HTML proper use of HTML markup logical order validate it for screen readers, search engine crawlers, etc. 2. Write some core CSS something that looks OK on all devices e.g. single-column layout for the narrowest reasonable viewport widths 3. Write successive media queries that apply extra styles for relevant breakpoints e.g. multi-column when viewport min-width allows it e.g. even ultimately a fixed-width design for very wide viewports

5 of 13 Example /* Core */ @import url(https://fonts.googleapis.com/css?family=shadows+into+light); html { background-image: url('mint_stripes.jpg'); /* Stripes background mint green: http://www.publicdomainpictures.net/ view-image.php?image=148956&picture=stripes-background-mint-green Licenced under CC BY 1.0 (https://creativecommons.org/publicdomain/zero/1.0/) */ background-color: rgb(204, 239, 219); * { margin: 0; padding: 0; width: 70%; margin: 1em auto; background-color: rgb(1, 92, 3); color: white; border: 1em solid rgb(1, 92, 3); border-radius: 1em; font-size: 16px; font-family: 'Shadows Into Light', cursive; nav, main, aside { background-color: white; color: black; padding: 1em; border: 0.0625em solid rgb(204, 239, 219); border-radius: 1em;.cocktail { color: rgb(1, 92, 3); font-weight: bold; img { max-width: 100%; 6 of 13 /* Header */ header { padding: 2em; display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: baseline; header > h1 { font-size: 3em; header > p { font-size: 2em; /* Nav */ padding: 1em 0; background-color: rgb(204, 239, 219); text-align: center; nav ul { list-style: none; padding: 0 0.0625em; nav li li { background-color: white; border: 0.0625em solid rgb(204, 239, 219);

7 of 13 /* Main */ main { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-around; align-items: flex-start; main > h1, main > figure, main > p { flex-basis: 100%; main > section { flex-basis: 48%; min-width: 15em; border: 0.0625em solid rgb(204, 239, 219); border-radius: 1em; main > h1 { font-size: 2em; main > section > h1 { font-size: 1.5em; padding: 0 1rem; main > section > p { padding: 0 1rem; main > p { main ul, main ol { padding: 0 0 0 2.5em; main > figure, #warning { text-align: center;.attribution { display: block; font-size: 0.6em; 8 of 13 /* Aside */ aside > h1 { font-size: 1.5em; aside > p { border-bottom: 0.0625em solid rgb(204, 239, 219); /* Footer */ footer { padding: 2em;

9 of 13 /* Two-column layout */ @media screen and (min-width: 50em) { nav ul { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-around; nav ul li { flex-basis: 10em; display: grid; grid-template-columns: 75% 25%; grid-template-rows: auto; grid-template-areas: "upper-top upper-top" "lower-top lower-top" "middle-left middle-right" "bottom bottom" header { grid-area: upper-top; grid-area: lower-top; main { grid-area: middle-left; aside { grid-area: middle-right; footer { grid-area: bottom; 10 of 13 /* Three-column layout */ @media screen and (min-width: 70em) { text-align: left; background-color: white; padding: 1em 0; nav ul { padding: 0 0 0 2.5em; nav li li { border: 0; border-bottom: 0.0625em solid rgb(204, 239, 219); display: grid; grid-template-columns: 20% 55% 25%; grid-template-rows: auto; grid-template-areas: "top top top" "middle-left middle-middle middle-right" "bottom bottom bottom" header { grid-area: top; grid-area: middle-left; main { grid-area: middle-middle; aside { grid-area: middle-right; footer { grid-area: bottom;

11 of 13 /* Fixed-width three-column layout */ @media screen and (min-width: 80em) { width: 60em; Common breakpoints 320px For small screen devices, like phones, held in portrait mode 480px For small screen devices, like phones, held in landscape mode 600px Smaller tablets held in portrait mode 768px Ten-inch tablets held in portrait mode 1024px Ten-inch tablets held in landscape mode, as well as some laptop, netbook and desktop displays 1200px For widescreen displays, primarily laptop and desktop browsers But, there is a much wider range of devices and viewports than this table assumes the table is not future-proof 12 of 13 Breakpoints Let content determine breakpoints: "Start with the small screen first, then expand until it looks like shit. Time for a breakpoint!" Stephen Hay A breakpoint is any point at which you need a media query to get the page or one of its components to look right Some people now recommend using ems instead of pixels for the media queries This defines breakpoints proportionally and hence also works when the user scales the content It also encourages you to define breakpoints based on readability: people are most comfortable with lines of 45-75 characters

13 of 13 A final fix Many small-screen devices draw a distinction between the 'layout viewport' and the 'visual viewport' E.g. iphone layout viewport is 980 px wide but visual viewport is 320 px wide Web pages are drawn onto the layout viewport (e.g. CSS widths are based on this) But what you see is just part of it whatever fits into the visual viewport Zoom out to see more of it Question: Why do you think this is a problem for us? For RWD on these devices we need to override this default behaviour by making the two viewports of equal size Two alternative ways of doing this Add the following inside the head element of your HTML: <meta name="viewport" content="initial-scale=1.0, width=device-width" /> (but this is not part of standard HTML and it is undesirable to define visual styles in HTML) Or add the following to your CSS: @viewport{width:device-width (but this is so new that it is not yet widely supported by browsers) For now, maybe do both!