© anselm spoerriinfo + web tech course information technologies info + web tech course anselm...

26
© Anselm Spoerri Info + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) SC&I @ Rutgers University [email protected] [email protected]

Upload: kimberly-gregory

Post on 16-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

© Anselm SpoerriInfo + Web Tech Course

InformationTechnologies

Info + Web Tech Course

Anselm Spoerri PhD (MIT)SC&I @ Rutgers University

[email protected]@gmail.com

© Anselm SpoerriInfo + Web Tech Course

Lecture 5 - Overview

HTML Elements– Recap: Hierarchy of Tags | Block and Inline Elements

– div | id | class

HTML5– HTML5 Key New Features

Cascading Style Sheet = CSS– Formatting Rules

– Inline | Internal | External specification of CSS rules

CSS3– CSS3 Key New Features

CSS Demo

Lectures – Week 5 Contenthttp://comminfo.rutgers.edu/~aspoerri/Teaching/InfoTech/Lectures.html#week5

© Anselm SpoerriInfo + Web Tech Course

Recap & New – Web Basics: HTML Elements & Tags

HTML is made up of elements<tag>Content</tag>(read as: open tag, content, close tag)

Three major elements needed on HTML page<html> - container for all of our HTML code

<head> - put data for browser and other machines

<body> - put content to show to the user

Block-level elements take up own space vertically(<p>, <h1-6>, <header> <nav>, <main>, <article>, <footer>)

<div> page division and used style blocks of content

Inline-level elements placed inside other elements

(<a>, <img>, <strong>, <em>, …)

© Anselm SpoerriInfo + Web Tech Course

Page Layout – DIVs

Two methods for creating Web Page Layout‒ Tables (last lecture)

‒ HTML5, DIVs and CSS (this lecture)

Structure Your Pages URL

‒ Divide logical sections of document into div elements

Produces “linear / natural flow” of elements

pageContent

header

navigation

main content

footer

<div>

<div> header content </div>

<div> navigation content </div>

<div> main content </div>

<div> footer content </div>

</div>

© Anselm SpoerriInfo + Web Tech Course

Page Structure – Hierarchy & Naming Elements

Hierarchical Structure of Web pages‒ Elements contained inside another element (latter = parent, former = child)

Naming Elements

‒ id="name" can be applied only once unique

#idName {…} define CSS rule

‒ class="name" can be applied many times

.className {…} define CSS rule

Useful with div (content blocks) and span (inline text) elements

<html> <body> <div> page content </div>

</body>

</html>

© Anselm SpoerriInfo + Web Tech Course

Page Layout – DIVs with IDs

Name div elements with unique IDs

pageContent

header

navigation

main content

footer

<div id="pageContent">

<div id="header"> text/images/links </div>

<div id="navi"> text/images/links </div>

<div id="content"> text/images/links </div>

<div id="footer"> text/images/links </div>

</div>

© Anselm SpoerriInfo + Web Tech Course

Page Layout – HTML5 tags

Use tags that represent meaning of content elements

pageContent

header

navigation

main content

footer

<div id="pageContent">

<header> text/images/links </header>

<nav> text/images/links </nav>

<main> text/images/links </main>

<footer> text/images/links </footer>

</div>

© Anselm SpoerriInfo + Web Tech Course

HTML5 – Intro

Why HTML5?– Reduce the need for external plugins (like Flash)– Better error handling– More markup to replace scripting– HTML5 should be device independent– Based on HTML, CSS, DOM, and JavaScript

What is HTML5‒ HTML5 specification – http://dev.w3.org/html5/spec/‒ Officially Working Draft | “living standard”

Browser Support for HTML5– HTML5 not yet official standard, no browser provides full HTML5 support.– But all major browsers continue to add support for new HTML5 features.– Understanding & implementing features is what matters.

© Anselm SpoerriInfo + Web Tech Course

HTML5 – New Capabilities

http://www.w3schools.com/html5/default.asp

Video specifies standard way to embed video (no plug-in)

Audio specifies standard way to embed audio (no plug-in)

Drag and Drop any element can be draggable what to drag | where to drop | do the drop

Canvas used to draw graphics, on the fly, on web page

SVG supported Scalable Vector Graphics to draw shapes

Geolocation can determine user's position with permission

Web Storage better local storage within browser than cookies

Web Workers JavaScript runs in background without affecting page performance

Server-Sent Events page gets automatic updates from server

© Anselm SpoerriInfo + Web Tech Course

HTML5 – DOCTYPE | charset | lang | CSS & JavaScript links

‒ HTML5 DOCTYPE: <!DOCTYPE html>

‒ not case sensitive | version dropped

‒ all browsers recognize shortened DOCTYPE & render in strict modeand deprecated elements will not work

‒ Specify Character Set: <meta charset="UTF-8" />

‒ Specify Language: <html lang="en">

<!DOCTYPE html> <html lang="en"> <head><meta charset="utf-8" />

‒ Script and Link Declarations: type attribute optional

<link rel="stylesheet" href="styles.css" />

<script src="scripts.js"></script>

© Anselm SpoerriInfo + Web Tech Course

HTML5 – New Elements

New Media Elements<audio> sound content<video> video or movie<source> multiple media resources for <video> and <audio><embed> container for external application or interactive content (a plug-in)<track> text tracks for <video> and <audio>

New Form Elements–New form controls, like calendar, date, time, email, url, search

New Semantic / Structural Elements‒ header, nav, aside, section, article and footer

‒ Focus on your content and consider semantics of each element

‒ Use div if you need containing element strictly for style purposes

‒ Some older browsers treat new elements like inline elements

header, footer, nav, article, aside, section { display: block; }

© Anselm SpoerriInfo + Web Tech Course

HTML5 – New Semantic / Structural Elements

‒ header element‒ Used to contain headline(s) for a page and/or section.

‒ Can contain logos and navigational aids.

‒ nav element‒ Contains major navigation links.

‒ Often contained by header.

‒ aside element‒ Contains related information, such as sidebar or pull-quotes.

‒ section element‒ Contains content that is related or grouped thematically.‒ Only if its content has own self-contained outline (h1,… h6).‒ Do not use simply for styling purposes – use divs and spans instead.

‒ article element‒ Stand-alone content such as a blog entry.

‒ footer element‒ Contains information about a page and/or section.

© Anselm SpoerriInfo + Web Tech Course

HTML5 – Element Flowchart

http://html5doctor.com/happy-1st-birthday-us/#flowchart

© Anselm SpoerriInfo + Web Tech Course

CSS

Cascading Style Sheets = CSS

‒ Collection of Formatting Rules

‒ Control Appearance of web page: blocks and text

‒ Ensure a more Consistent Treatment of Page Layout and Appearance in Browsers

‒ Separation of Content from Presentation

– Easier to Maintain Appearance since Make Change in Single Location

– Simpler and Cleaner HTML code shorter loading times

© Anselm SpoerriInfo + Web Tech Course

CSS (cont.)

Cascading Style Sheets (CSS)

‒ Control Text propertiesSpecific fonts and font sizes; bold, italics, underlining, and text shadows;

text color and background color; link color and link underlining; etc.

‒ Control Format & Position of Block-level Elements Set margins and borders for block-level elements; position them in a specific

location; add background color; float text around them; etc.

‒ Liquid layouts: expand/contract based on Browser width.

‒ Easy to apply Same Layout to Whole Site and only need to modify external CSS file.

‒ Minus: Not all browsers support CSS the same way.

© Anselm SpoerriInfo + Web Tech Course

CSS (cont.)

CSS Style Sheet stored

a) External CSS style sheet (.css file linked to page and using a link or an @import rule in the head section of a document).

b) Internal (or embedded) CSS style sheet (included in style tag in head portion of an HTML document).

c) Inline styles (defined within specific tag instance in HTML document) Using Inline styles is not recommended.

CSS Rule = Selector and Block of Declarations

Enclosed by {...} brackets and separated by ;

Declaration = Property: Value;

© Anselm SpoerriInfo + Web Tech Course

CSS – General Structure of CSS Rule

Basic syntax for Internal and External CSS:

selector {property1: value1; property2: value 2;}

HTML tag you want to modify

Value you want property to takeProperty you want to change

p { text-align: left; color: black; font-family: Arial; }

causes

Font to be left-alignedFont to be Arial and black

© Anselm SpoerriInfo + Web Tech Course

CSS Rules – id and class Rules in Internal Style Sheet

<head>

<style type="text/css">

/* Comment: pageContent ID and define font to use for page and the top and left margins as well page width. This pageContent div contains all the other

divs */#pageContent {

font-family: Verdana, Geneva, sans-serif;

font-size: 12px;

margin-top: 10px;

margin-left: 50px;

width: 500px;

}

/* blue text class */

.blueText {color:#009;

}

</style>

</head>

© Anselm SpoerriInfo + Web Tech Course

CSS Rules – id and class Rules Applied in <body>

<body>

<div id="pageContent">

<div id="content">

<h1>Heading1</h1>

<p class="blueText">Open paragraph</p>

</div>

</div>

</body>

© Anselm SpoerriInfo + Web Tech Course

Location of CSS Style Definition

Inline style (causes only the tag to have desired properties)

<p style="font-family:Arial; color:blue">Something blue </p>

Internal stylesheet (specific to a document)

– Causes all tags in document to have property– <style> tag inside <head> tag of document

<head> <style type="text/css"> p { font-family:Arial; color:blue;} </style> </head>

External stylesheet (can control multiple documents)– Ensure consistent appearance of website

<head> <link rel="stylesheet" href="mystyle.css" type="text/css" /></head>

© Anselm SpoerriInfo + Web Tech Course

CSS – Cascasde of How Rules are Applied

Style Rules “Cascade” from broad to narrow:

– Browser’s Default Behavior

– External Style Sheet

– Internal Style Sheet

– Inline Style

© Anselm SpoerriInfo + Web Tech Course

CSS3 – Intro

http://www.w3schools.com/css3/default.asp

CSS3 backwards compatible, don’t have to change existing designs.

Borders Rounded, add shadow and use image as border.

Backgrounds new background properties and greater control.

Text Effects new features such as text-shadow or word-wrap.

Fonts can use font you like by including font file on server.

2D Transforms move, scale, turn, spin and stretch elements.

3D Transforms format elements using 3D transforms.

Transitions add effect when changing from one style to another, such as on mouseover or mouseout events.

Animations specify CSS style inside @keyframes rule and animation will gradually change from the current style to the new style.

Multiple Columns can create multiple columns for laying out text.

User Interface user can resize elements and other features supported.

© Anselm SpoerriInfo + Web Tech Course

CSS Demo – Step 1

Step 1

‒ Download “startPage.html” fromhttp://comminfo.rutgers.edu/~aspoerri/Teaching/InfoTech/Lectures/Lec5/Steps

‒ Save “startPage” as “page1.html” in folder “week5”

‒ Create nested div structure

pageContent,header, navi, content, footer

‒ Assign id name to div

© Anselm SpoerriInfo + Web Tech Course

CSS Demo – Step 2

Step 2

‒ Create Internal CSS Style Sheet

<style type="text/css">

‒ Create CSS Rule for id="pageContent"

font-family: Verdana, Geneva, sans-serif;font-size: 12px;margin-top: 10px;margin-left: 50px;width: 500px;

‒ Create CSS Rule for class="blueText"

color:#009;

© Anselm SpoerriInfo + Web Tech Course

CSS Demo – Step 3

Step 3

‒ Create CSS Rule for id="header" in HTML5 for <header>

font-size: 9px;border-bottom-width: thin;border-bottom-style: solid;border-bottom-color: #333;

‒ Create CSS Rule for id="navi" in HTML5 for <nav>

font-size: 14px;background-color: #E1E3F7;padding: 5px;margin-top: 5px;

© Anselm SpoerriInfo + Web Tech Course

CSS Demo – Step 4

Step 4

‒ Create CSS Rule for id="content" in HTML5 for <main>

font-size: 12px;

‒ Apply class="blueText"

<p> tag inside div with id="content"

‒ Create CSS Rule for id="footer" in HTML5 for <footer>

font-size: 10px;border-top-width: thin;border-top-style: solid;border-top-color: #666;