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

Similar documents
Responsive Web Design (RWD)

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

Zen Garden. CSS Zen Garden

COMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts

Styles, Style Sheets, the Box Model and Liquid Layout

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

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

Client-Side Web Technologies. CSS Part II

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

COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts

HTML Organizing Page Content

COMP519 Web Programming Lecture 7: Cascading Style Sheets: Part 3 Handouts

Page Layout Using Tables

Create a three column layout using CSS, divs and floating

Introducing CSS Flexbox Layout

CSC Website Design, Spring CSS Flexible Box

CHRIS SAUVE 2

Notes - CSS - Flexbox

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

subject to an additional IP rights grant found at polymer.github.io/patents.txt -->

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

CSS: The Basics CISC 282 September 20, 2014

CS193X: Web Programming Fundamentals

Cascading Style Sheets for layout II CS7026

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

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

FEWD START SCREENCAST!!!!

Advanced CSS. Slava Kim

HTML Organizing Page Content

Adding CSS to your HTML

16A CSS LAYOUT WITH FLEXBOX

Using CSS for page layout

Welcome Please sit on alternating rows. powered by lucid & no.dots.nl/student

ICT IGCSE Practical Revision Presentation Web Authoring

Graduating to Grid. An Event Apart Orlando

Chapter 7 BMIS335 Web Design & Development

FLEXBOX FOR RESPONSIVES WEBDESIGN

McMaster Brand Standard for Websites

WEBSITE PROJECT 2 PURPOSE: INSTRUCTIONS: REQUIREMENTS:

CSS Box Model. Cascading Style Sheets

Header. Article. Footer

INFS 2150 / 7150 Intro to Web Development / HTML Programming

CSS for Page Layout Robert K. Moniot 1

IMY 110 Theme 7 HTML Tables

COMP519 Web Programming Autumn Cascading Style Sheets

EXPLORE MODERN RESPONSIVE WEB DESIGN TECHNIQUES

Appendix D CSS Properties and Values

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

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

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

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.

CSS.

How to lay out a web page with CSS

Media Types & Media Features

Website Development with HTML5, CSS and Bootstrap

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

Assignments (4) Assessment as per Schedule (2)

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

HTML-5.com itemscopehttp://data-vocabulary.org/breadcrumb<span itemprop="title">html 5</span> itemscopehttp://data-vocabulary.

Fundamentals of Web Technologies. Agenda: CSS Layout (Box Model) CSS Layout: Box Model. All HTML elements can be considered as a box or a container

Cascading Style Sheets (CSS)

Chapter 3 Style Sheets: CSS

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

Indian Institute of Technology Kharagpur. HTML Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

ITNP43: HTML Lecture 4

Cascading Style Sheets Level 2

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

YouTube Break.

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

In this tutorial, we are going to learn how to use the various features available in Flexbox.

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Table Basics. The structure of an table

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

HIERARCHICAL ORGANIZATION

COMS 359: Interactive Media

ICT IGCSE Practical Revision Presentation Web Authoring

Taking Fireworks Template and Applying it to Dreamweaver

CMPT 165: More CSS Basics

ADOBE 9A Adobe Dreamweaver CS4 ACE.

CSCU9B2: Web Tech Lecture 3

USER GUIDE MADCAP FLARE Tables

The Importance of the CSS Box Model

CSS: formatting webpages

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar with Dynamic Background Image

Dreamweaver MX Overview. Maintaining a Web Site

HTML/XML. HTML Continued Introduction to CSS

AGENDA :: MULTIMEDIA TOOLS :: CLASS NOTES

Final Exam Study Guide

Using Dreamweaver CS6

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

UNSW Global Website Branding Guidelines. Website Brand Guidelines

Media-Specific Styles

IDM 222. Web Design II. IDM 222: Web Authoring II 1

CS7026 Media Queries II. Different Screen Size Different Design

Learning Objectives. Review html Learn to write a basic webpage in html Understand what the basic building blocks of html are

Transcription:

COMP519 Web Programming Lecture 8: Cascading Style Sheets: Part 4 Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

Contents 1 Layout Via Divs Relevant Properties 2 CSS Grid Layout Overview Defining a Grid Layout Placing Elements on a Grid Example 3 CSS Flexbox Layout Overview Defining a Flexbox Layout Example 4 Adaptive versus Responsive Design 5 Further Reading COMP519 Web Programming Lecture 8 Slide L8 1

Layout Via Divs Layout Via Divs: Overview For a long time, web page layout was based on the extensive use of div elements A web page would typically consist of roughly a handful of div elements as follows: <div id =" header ">... </div > <div id =" nav ">... </div > <div id =" main "> <div id =" content ">... </ div > <div id =" ads ">... </div > </div > <div id =" footer ">... </div > possibly with additional div elements inside each of those Layout is then a matter of arranging those div elements Decisions on layout are a matter of design, not of technical possibility there is typically not one right answer this is not a topic for this module (web programming vs web design) COMP519 Web Programming Lecture 8 Slide L8 2

Layout Via Divs Divs and Properties (1) Relevant Properties By default, a div element takes up the whole width of a browser window and there is a line break before and after it Changes almost always need to be made to achieve the desired layout CSS properties that we can use to make those changes include Property width height margin Explanation / Example values Width of an element 1000px 90% 90% of the width of the containing element Height of an element 200px 10% 10% of the height of the containing element All four margins of an element auto centre horizontally within containing element COMP519 Web Programming Lecture 8 Slide L8 3

Layout Via Divs Divs and Properties (1) Relevant Properties By default, a div element takes up the whole width of a browser window and there is a line break before and after it Changes almost always need to be made to achieve the desired layout CSS properties that we can use to make those changes include Property float clear Explanation / Example values Whether and in which direction an element should float left element floats to the left of its container right element floats to the right of its container Whether and how an element must be (cleared) below floating elemnts left element moves down to clear past left floats right element moves down to clear past right floats both element moves down to clear past all floats COMP519 Web Programming Lecture 8 Slide L8 4

Layout Via Divs Layout Via Divs: Example (1) Relevant Properties A common layout of the top-level div elements is the following with the width of header, nav, main, footer fixed to a value between 900px and 1000px <body > <div id =" header "> header </div > <div id =" nav "> nav </div > <div id =" main "> <div id =" content "> content </div > <div id =" ads "> ads </div > </div > <div id =" footer "> footer </div > </body > COMP519 Web Programming Lecture 8 Slide L8 5

Layout Via Divs Layout Via Divs: Example (1) Relevant Properties A common layout of the top-level # header { width : 1000 px; div elements is the following height : 100 px; background - color : blue ; margin : auto ; } # nav { width : 1000 px; height : 50 px; background - color : green ; margin : auto ; } # main { width : 1000 px; margin : auto ; } # content { width : 800 px; height : 400 px; with the width of header, nav, background - color : yellow ; float : left ; } main, footer fixed to a value # ads { width : 200 px; height : 400 px; between 900px and 1000px background - color : orange ; float : right ; } # footer { width : 1000 px; height : 50 px; clear : both ; margin : auto ; background - color : blue ;} http://cgi.csc.liv.ac.uk/~ullrich/comp519/examples/layout1.html COMP519 Web Programming Lecture 8 Slide L8 6

Layout Via Divs Ids, Classes, Elements Relevant Properties In the example, we assigned unique a id to each div element and associated a style directive with each of those ids Alternatively, we could have assigned a unique class to each div element and associated a style directive with each of those classes In HTML5, we would use the appropriate elements like header, nav, etc instead of div elements We would then associate a style directive with each of those elements header { width : 1000 px; height : 100 px; background - color : blue ; margin : auto ; } nav { width : 1000 px; height : 50 px; background - color : green ; margin : auto ; } <body > <article > <header > </ header > <nav > </nav > <section > </ section > <aside > </ aside > <footer > </ footer > </ article > </body > COMP519 Web Programming Lecture 8 Slide L8 7

Layout Via Divs Divs and Properties (2) Relevant Properties So far, we have positioned div elements relative to each other This means the arrangements of div elements as a whole can move and can move out of view if the user scrolls up or down in a browser window CSS properties that we can use to change that include Property position Explanation / Example values Specifies how an element is positioned in a document fixed The element is removed from the normal document flow; no space is created for the element in the page layout; it is positioned relative to the screen s viewport using properties top, bottom left, right and does not move when scrolled COMP519 Web Programming Lecture 8 Slide L8 8

Layout Via Divs Relevant Properties Divs and Properties (2) CSS properties required for position include Property top bottom left right Explanation / Example values When position is set to absolute or fixed, specifies the distance between the element s top edge and the top edge of its containing block 10px 10px off top edge Analogous to top for the element s bottom edge and the bottom edge of its containing block 20% 20% of the width of the containing block Analogous to top for the element s left edge and the left edge of its containing block auto Analogous to right for the element s left edge and the left edge of its containing block inherit inherit from parent element COMP519 Web Programming Lecture 8 Slide L8 9

Layout Via Divs Layout Via Divs: Example (2) Relevant Properties We want to achieve the same layout as before but with header, nav and footer fixed in position Wo do so with slightly different approaches used in the style directives for each of these three elements # header { width : 1000 px; height : 100 px; background - color : blue ; position : fixed ; top : 0px; left : 50%; margin - left : -500 px; } # nav { width : 1000 px; height : 50 px; background - color : green ; position : fixed ; top : 100 px; left : 0px; right : 0px; margin : auto ; } # main { width : 1000 px; padding - top : 142 px; margin : 0 auto ; } http://cgi.csc.liv.ac.uk/~ullrich/comp519/examples/layout2.html COMP519 Web Programming Lecture 8 Slide L8 10

Layout Via Divs Layout Via Divs: Example (2) Relevant Properties We want to achieve the same layout as before but with header, nav and footer fixed in position Wo do so with slightly different approaches used in the style directives for each of these three elements # content { width : 800 px; height : 1000 px; background - color : yellow ; float : left ; } # ads { width : 200 px; height : 1000 px; background - color : orange ; float : right ; } # footer { width : 1000 px; height : 50 px; background - color : blue ; position : fixed ; bottom : 0px; left : 50%; transform : translate ( -50%,0%); } http://cgi.csc.liv.ac.uk/~ullrich/comp519/examples/layout2.html COMP519 Web Programming Lecture 8 Slide L8 11

Layout Via Divs Adaptive Design Revisited Relevant Properties One fixed, rigid layout is unlikely to be suitable for every medium that a user might use to access an HTML document We have seen that the media-attribute of the link element allows us to select which external style sheets to use for which medium, e.g. <link rel =" stylesheet " type =" text / css " media =" screen " href =" browser. css "> <link rel =" stylesheet " type =" text / css " media =" print " href =" print. css "> However, if the style directives in the these different style sheets are largely identical, this is not an optimal approach the same style directives exist in several files, changes are error prone HTML5 provides three meachanisms to better deal with such a situation Import rules Media rules Support rules COMP519 Web Programming Lecture 8 Slide L8 12

Layout Via Divs Importing CSS style files Relevant Properties The @import CSS at-rule is used to import style directives from other style sheets @import url ; @import url list-of-media-queries ; Examples: @import url (" http :// cgi. csc. liv.ac.uk/ styles / common. css "); @import " screen-specific. css " screen ; @import print-specific. css print ; These rules must precede all other types of rules and directives except @charset rules A @charset CSS at-rule specifies the character encoding used in a style sheet, for example: @charset " utf-8 "; The default character encoding is UTF-8 Useful / used when attributes like content are given values involving non-ascii characters COMP519 Web Programming Lecture 8 Slide L8 13

Layout Via Divs Media Rules and Media Queries Relevant Properties Within a style sheet, @media at-rules can used to conditionally apply styles to a document depending on the result of media queries @media list-of-media-queries { group-rule-body } where group-rule-body is either another @media at-rule, @supports at-rule, or list of style directives Examples: @media print { body { font-size : 10 pt; } } @media screen and ( resolution > 150 dpi ) { body { font-size : 13 px; } } The language for media queries is an extension of the one we have seen for the media attribute COMP519 Web Programming Lecture 8 Slide L8 14

Layout Via Divs Feature Queries Relevant Properties Within a style sheet, @support at-rules can be used to conditionall apply styles to a document depending on the result of feature queries @supports feature-query { group-rule-body } A feature query is basically a boolean combination (using and, or, not) of property:value pairs For each property:value it will be evaluated whether the browser used to process the style sheet supports this specific CSS feature and then works out the truth value for the feature query overall Examples: @supports ( display : flex ) { div { display : flex ; } } @supports not ( display : flex ) { div { float : left ; } } COMP519 Web Programming Lecture 8 Slide L8 15

CSS Grid Layout CSS Grid Layout Overview CSS Grid Layout is a two-dimensional grid-based layout system Such layout systems are motivated by the observation that most web layouts can be seen as grids where elements are placed on one or more grid cells Height and width of grid columns and grid rows will in general vary Sample page layout row 1 Underlying grid and allocation of elements to grid cells col 1 col 2 col 3 col 4 header row 2 nav row 3 content ads row 4 footer COMP519 Web Programming Lecture 8 Slide L8 16

CSS Grid Layout Defining a Grid Layout Defining a Grid Layout CSS properties of Grid include display: grid defines an element as grid container grid-template-columns: track-size [col-name] track-size... specifies the size and names of columns grid-template-rows: track-size [row-name] track-size... specifies the size and names of rows track-size can be auto, a length, a percentage, or a fraction of the free space These properties allow to specify a grid, including the size of each column and each row COMP519 Web Programming Lecture 8 Slide L8 17

CSS Grid Layout Placing Elements on a Grid Placing Elements on a Grid One way to place an element on the grid is to specify in which column/row it starts (top, left corner) and in which column/row it ends (bottom, right corner) using the following properties grid-column-start: cell grid-column-end: cell grid-row-start: cell grid-row-end: cell cell can take the following values: number column number / row number name name of a column / row span number number of tracks covered span name span until name is reached auto automatic COMP519 Web Programming Lecture 8 Slide L8 18

CSS Grid Layout Placing Elements on a Grid Placing Elements on a Grid An alternative way to place elements on the grid is to assign grid names to the elements and to use a grid template that references those names: grid-area: area-name assign a grid area name to an element grid-template-areas: "area-name. none..." "..." associates grid area names with grid cells This is only a glimpse of the possibilities of the CSS Grid Layout System COMP519 Web Programming Lecture 8 Slide L8 19

CSS Grid Layout CSS Grid Layout: Example We want to replicate the same layout as before: Example <body > <article > <header > </ header > <nav > </nav > <section > </ section > <aside > </ aside > <footer > </ footer > </ article > </body > article { display : grid ; grid - template - rows : 100 px 50 px auto 50 px; grid - template - columns : auto 800 px 200 px auto ; grid - template - areas : ". header header." ". nav nav." ". content ads." ". footer footer."; } header { grid - area : header ; background - color : blue ; } nav { grid - area : nav ; background - color : green ; } section { grid - area : content ; background - color : yellow ; } aside { grid - area : ads ; background - color : orange ; } footer { grid - area : footer ; background - color : blue ; } http://cgi.csc.liv.ac.uk/~ullrich/comp519/examples/layout3.html COMP519 Web Programming Lecture 8 Slide L8 20

CSS Flexbox Layout CSS Flexbox Layout Overview CSS Flexbox Layout is a simpler layout system, typically used for parts of a web page, not the whole page Flexbox distinguishes between flex containers and flex items within those containers Unlike Grid, Flexbox distinguishes between a primary main axis and a secondary cross axis The main axis is not necessarily horizontal, its direction is determined by flex-direction COMP519 Web Programming Lecture 8 Slide L8 21

CSS Flexbox Layout Defining a Flexbox Layout CSS properties of Flexbox include display: flex defines an element as a flexbox container Defining a Flexbox Layout flex-direction: row row-reverse column column-reverse defines the direction of the main axis, for example, with row the direction is left to right flex-wrap: nowrap wrap wrap-reverse whether and how flex items wrap when the main axis is full, for example, with wrap-reverse, flex items will wrap onto multiple lines from bottom to top along the cross axis flex-flow: direction-option wrap-option combines flex-direction and flex-wrap COMP519 Web Programming Lecture 8 Slide L8 22

CSS Flexbox Layout Flexbox Layout Properties Defining a Flexbox Layout CSS properties of Flexbox include justify-content: justify-option defines the alignment along the main axis justify-option can take the following values: Images courtesy of Chris Coyier: A Complete Guide to Flexbox. CSS-Tricks. 28 September 2017. https://css-tricks.com/snippets/css/a-guide-to-flexbox/ (accessed 18 October 2017). COMP519 Web Programming Lecture 8 Slide L8 23

CSS Flexbox Layout Flexbox Layout Properties Defining a Flexbox Layout CSS properties of Flexbox include align-content: align-option defines the use of extra space along the cross axis align-option can take the following values: Images courtesy of Chris Coyier: A Complete Guide to Flexbox. CSS-Tricks. 28 September 2017. https://css-tricks.com/snippets/css/a-guide-to-flexbox/ (accessed 18 October 2017). COMP519 Web Programming Lecture 8 Slide L8 24

CSS Flexbox Layout CSS Flexbox Layout: Example Example HTML <nav > <a href ="#" > Computer Science </a> <a href ="#" > Electrical Engineering and Electronics </a> <a href ="#" > Physics </a> </nav > CSS a { text - align : center } nav { background - color : LightGreen ; display : flex ; flex - direction : row ; justify - content : space - around ; } /* Narrow screen width */ @media all and ( max - width : 900 px) { nav { flex - direction : column ; } } Width = 1000px Width = 900px http://cgi.csc.liv.ac.uk/~ullrich/comp519/examples/layout4.html COMP519 Web Programming Lecture 8 Slide L8 25

Adaptive versus Responsive Design Adaptive versus Responsive Design Adaptive Design Uses a limited number of different web pages and/or different styles depending on media devices and media attributes Responsive design Uses a single web page and style that through the use of media queries, flexible grids, relative units and responsive images tries to adjust to any media device with any media attributes at any time COMP519 Web Programming Lecture 8 Slide L8 26

Adaptive versus Responsive Design Adaptive versus Responsive Design Adaptive Design Uses a limited number of different web pages and/or different styles depending on media devices and media attributes Responsive design Uses a single web page and style that through the use of media queries, flexible grids, relative units and responsive images tries to adjust to any media device with any media attributes at any time There are no generally agreed definitions of adaptive design and responsive design It is often debatable whether a website uses adaptive design or responsive design (or neither) There is even more debate which one is better Most/all of the examples we have seen use adaptive design, but this was done for effect COMP519 Web Programming Lecture 8 Slide L8 27

Adaptive versus Responsive Design Style Guide HTML and CSS provide a lot of features, but these must be used sensibly just because a feature exists does not mean it be used Do not use features that distract from the content of your web page Use (non-default) colours and fonts carefully no purple text on pink background no weird fonts (that includes Comic Sans) mainly use a dark font on a light background Remember that an estimated 8-10% of people have some type of colour-blindness avoid red/green colour combinations Remember that some people use screen readers to read the content of web pages always include alt properties for images COMP519 Web Programming Lecture 8 Slide L8 28

Adaptive versus Responsive Design Style Guide Use relative units to specify font sizes, not fixed pixel sizes Use images appropriately avoid bright background images that make foreground text hard to read avoid clickable images instead of standard buttons for links as they can slow down the download of your page Do not rely on specific window size or specific font size for layout as the user might change those use an adaptive or responsive design Break a large web page into several smaller ones or provide a menu for navigation Utilise style sheets to make changes to style and layout easy and ensure consistency across a set of web pages Stick to standard features and test several browsers COMP519 Web Programming Lecture 8 Slide L8 29

Further Reading Revision and Further Reading Read 1 Chris Coyier: A Complete Guide to Flexbox. CSS-Tricks. 28 September 2017. https: //css-tricks.com/snippets/css/a-guide-to-flexbox/ (accessed 18 October 2017). 2 Chris House: A Complete Guide to Grid. CSS-Tricks. 13 September 2017. https: //css-tricks.com/snippets/css/complete-guide-grid/ (accessed 18 October 2017). 3 Mozilla and individual contributors: CSS Grid Layout. MDN Web Docs, 5 October 2017. https://developer.mozilla.org/en-us/docs/web/css/ CSS_Grid_Layout (accessed 19 October 2017). COMP519 Web Programming Lecture 8 Slide L8 30