61
Hypertext Markup Language HTML Chapter 2 Supporting Material for “Using Google App Engine” - O’Reilly and Associates www.appenginelearn.com

Hypertext Markup Language HTML Chapter 2

  • Upload
    others

  • View
    28

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Hypertext Markup Language HTML Chapter 2

Hypertext Markup LanguageHTML

Chapter 2

Supporting Material for “Using Google App Engine” - O’Reilly and Associateswww.appenginelearn.com

Page 2: Hypertext Markup Language HTML Chapter 2

Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License.http://creativecommons.org/licenses/by/3.0/.

Copyright 2009, Charles Severance

Page 3: Hypertext Markup Language HTML Chapter 2

Internet

HTML

CSS

JavaScript

AJAX

HTTP Request

Response GET

POST

Python

Templates

Data Storememcache

Page 4: Hypertext Markup Language HTML Chapter 2

The big picture...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>University of Michigan</title>....

A web server produces HTML which is handed to a browser which

needs to lay it out in a blink of an eye and have it pixel perfect as god

as a print brochure.

Page 5: Hypertext Markup Language HTML Chapter 2

HTML

• A way of marking up text to indicate that some text is different than other text

• We “tag” portions of the text to communicate meaning

<h1>Google App Engine: About</h1><p>Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful.</p>

Page 6: Hypertext Markup Language HTML Chapter 2

<h1>Google App Engine: About</h1><p>Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful.</p>

Whitespace and line wrapping.

Page 7: Hypertext Markup Language HTML Chapter 2

<li><a href="mailto:[email protected]" title="Send mail to [email protected]">[email protected]</a></li>

Learning from“View Source”

Page 8: Hypertext Markup Language HTML Chapter 2

Evolution of HTML

Page 9: Hypertext Markup Language HTML Chapter 2

The Web is a Young Technology

• Invented in early 1990’s

• Popular in 1994

• Robert Cailliau - coFounder of the World-Wide-Web

http://www.dr-chuck.com/media.php?id=70

Page 10: Hypertext Markup Language HTML Chapter 2

19952007

HTML has evolved a *lot* over the years - as computers and networks have gotten faster.

Page 11: Hypertext Markup Language HTML Chapter 2

An Iterative Process

• Designers want to do something

• They figure out how to do it with current generation browsers

• We figure out requirements - but HMTL gets uglier and quirkier - then the HTML starts to break

• We develop new standards that handle new requirements in an elegant manner

• New Browsers arrive in the marketplace with the new standard

Page 12: Hypertext Markup Language HTML Chapter 2

History of HTML / CSS• HTML 1.0 - 1993 - The Good Old Days - life was simple

• HTML 2.0 - 1995 - Some interesting layout features - abused

• CSS 1 - 1996

• HTML 3.2 - 1997

• HTML 4.0 - 1997 - Layout moving toward CSS

• CSS Level 2 - 1998

• HTML 4.01 - 1999 - What we use today

HTML has evolved a *lot* over the years - as computers and networks have gotten faster.

Page 13: Hypertext Markup Language HTML Chapter 2

The Good Old Days

<h1>Hello World</h1>Hi there.<p><img src=”x.gif”>A Paragraph<ul><li>List one<li>List 2</ul>

In the good old days you wrote HTML and browsers

displayed it - since we wrote it by hand - and modems were slow - it was never too long and never too complex. The browser was never the rate

limiting factor.

Writing HTML was like using a simple, weak word

processor. The tags acted as formatting commands to the

browser.

Page 14: Hypertext Markup Language HTML Chapter 2

The Ugly Middle Ages

• Web Designers designed to browser capabilities - down to particular minor versions of browsers.

• Extensive testing was needed on lots of browsers

• Designers used tables, nested tables, and chopped up graphics to gain control of the look and feel or web pages to produce a “print-like” experience.

• HTML was UGLY, Hard to develop, and brittle - what looked superb on one browser - often was broken on another browser - even a later release of the same brower.

Page 15: Hypertext Markup Language HTML Chapter 2

The Modern Era

• HTML is clean and simple

• There is no presentation in HTML - font, color, spacing, etc etc

• No use of tables except for tabular data

• CSS controls all layout, and look and feel

• Still a bit challenging - but converging

Page 16: Hypertext Markup Language HTML Chapter 2

1990-1994 HTML was simple and pages looked pretty ugly.

1995-1999 HTML became more complex and each browser was different.

2000-2005 Browsers slowly supported CSS to varying levels. HTML was still ugly to support multiple browsers.

2005-2008 New browsers supported CSS. Old browsers were still pretty pervasive but diminishing.

2009+ The last “pre-CSS” browser (IE5) is < 0.1%

http://www.w3schools.com/browsers/browsers_stats.asp

Page 17: Hypertext Markup Language HTML Chapter 2

What does this mean for us?

• Don’t bother with the intermediate steps :)

• Either keep it simple - or do it well - simple does work

• If you want a professional site use all of the best practices

• Presentation in CSS + Semantic markup in HTML

• http://validator.w3.org/

• http://jigsaw.w3.org/css-validator/

Page 18: Hypertext Markup Language HTML Chapter 2

<h1>Google App Engine: About</h1><p>Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful.</p>

Whitespace and line wrapping.

Page 19: Hypertext Markup Language HTML Chapter 2

Tags have a beginning and end...

<h1>Google App Engine: About</h1><p>Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful.</p>

Page 20: Hypertext Markup Language HTML Chapter 2

HTML Tag Basics

<h1>Hello World</h1>

<img src=”x.gif” />

Start tag End tag

Self-closing tag

Attribute

A self closing tag does not need a corresponding end tag.

Tags “mark up” the HTML document. The tags are read and interpreted by the browser - but

now shown.

Page 21: Hypertext Markup Language HTML Chapter 2

What about < ‘s in HTML?

<h1>HTML: Special Characters</h1><p> Special characters are indicated by the &amp; character. We can use this to display &lt; and &gt; </p>

Page 22: Hypertext Markup Language HTML Chapter 2

HTML Links

• One of the key things about HTML is making a set of pages and making “hypertext” links amongst those pages

• Links are what make the “web” a “web” - it is a web of interlinked documents.

• The interlinked nature of the web leads to the “knowledge “ the search engines like Google appear to have

Page 23: Hypertext Markup Language HTML Chapter 2

A link is a “hot spot” on the page. It can be text or an image. Often it is visually marked to make it easier to “notice” so as to engouage users to

click!

“a” is short for “anchor” and “href” is short for “hypertext reference”

<h1>The First Page</h1><p>If you like, you can switch to the <a href="http://www.dr-chuck.com/page2.htm">Second Page</a>.</p>

Page 24: Hypertext Markup Language HTML Chapter 2

A link is a “hot spot” on the page. It can be text or an image. Often it is visually marked to make it easier to “notice” so as to engouage users to

click!

“a” is short for “anchor” and “href” is short for “hypertext reference”

<h1>The Second Page</h1><p>If you like, you can switch back to the <a href="page1.htm">First Page</a>.</p>

Page 25: Hypertext Markup Language HTML Chapter 2

<a href="page1.htm">First Page</a>

<a href="http://www.dr-chuck.com/page2.htm">Second Page</a>

Starttag

EndtagWhere to

go if clicked.Clickable

Text

Relative Reference

Absolute Reference

Page 26: Hypertext Markup Language HTML Chapter 2

Absolute .vs. Relative

<a href="page1.htm">First Page</a>

<a href="http://www.dr-chuck.com/page2.htm">Second Page</a>

Hypertext references can be a full URL - and refer to some other page on anywhere on the Internet.

Or the reference can be a file name that is assumed to be in the same folder as the current document (relative reference).

Page 27: Hypertext Markup Language HTML Chapter 2

Navigation With Anchor Tags

• Sometimes we want to make a menu that provides our users consistent navigation across page.

Page 28: Hypertext Markup Language HTML Chapter 2

A List ... <h1><a href="index.htm">AppEngineLearn</a></h1> <ul> <li><a href="sites.htm">Sites</a></li> <li><a href="topics.htm" >Topics</a></li> </ul> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

Bulleted List

Page 29: Hypertext Markup Language HTML Chapter 2

A List of Links... <h1><a href="index.htm">AppEngineLearn</a></h1> <ul> <li><a href="sites.htm">Sites</a></li> <li><a href="topics.htm" >Topics</a></li> </ul> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

Links

Page 30: Hypertext Markup Language HTML Chapter 2

Multiple Files

• We can put multiple files in the same directory and then use them in relative links.

csev$ ls -l -rw-r--r-- 1 csev staff 618 Dec 18 22:56 index.htm-rw-r--r-- 1 csev staff 883 Dec 18 22:57 sites.htm-rw-r--r-- 1 csev staff 679 Dec 18 22:57 topics.htmcsev$

Page 31: Hypertext Markup Language HTML Chapter 2

csev$ ls -l -rw-r--r-- 1 csev staff 618 Dec 18 22:56 index.htm-rw-r--r-- 1 csev staff 883 Dec 18 22:57 sites.htm-rw-r--r-- 1 csev staff 679 Dec 18 22:57 topics.htmcsev$

<h1><a href="index.htm">AppEngineLearn</a></h1> <ul> <li><a href="sites.htm">Sites</a></li> <li><a href="topics.htm" >Topics</a></li> </ul>

Navigation

Page 32: Hypertext Markup Language HTML Chapter 2

csev$ ls -l -rw-r--r-- 1 csev staff 618 Dec 18 22:56 index.htm-rw-r--r-- 1 csev staff 883 Dec 18 22:57 sites.htm-rw-r--r-- 1 csev staff 679 Dec 18 22:57 topics.htmcsev$

We create the appearance of a fixed

“menu” by including the navigation at the same

place in each page.

Page 33: Hypertext Markup Language HTML Chapter 2

Special File Names

• When a URL points to a directory in your web server, it looks for a file with a special name:

• index.html, index.htm, index.php, default.htm, etc..

• While there is a convention, the “default file” is configurable - so nothing is “sure”

• Usually index.htm or index.html is a safe bet

• This only works when viewing through a web server - when viewing from disk, you must view the file.

Page 34: Hypertext Markup Language HTML Chapter 2

<body> <!-- Make sure to style the h1 --> <h1>App Engine: Topics</h1> <ul> <li>Python Basics</li> <li>Python Functions</li> <li>Python Python Objects</li><!-- Leave these two out for a while <li>Hello World</li> <li>The WebApp Framework</li>--> <li>Using Templates</li> </ul></body> HTML Comments

Page 35: Hypertext Markup Language HTML Chapter 2

Images

Page 36: Hypertext Markup Language HTML Chapter 2

Begin Tag

End Tag

Begin TagBegin Tag

Show this when hovering, images are off, or for

screen readers.

Which image to display

Optional - makes display quicker.

Will resize to fit.

All information is communicated through the attributes of the img tag.

<img src="appengine.jpg"

width="142" height="109" alt="Google App Engine Logo"

style="float:right" />

Put the image on the right and wrap text around it.

Images

Page 37: Hypertext Markup Language HTML Chapter 2

Images <h1> <img src="appengine.jpg" width="142" height="109" alt="Google App Engine Logo" style="float:right"/> Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

In this case, the file appengine.jpg needs to be in the same directory as the file index.html.

Page 38: Hypertext Markup Language HTML Chapter 2

<h1> <img src="appengine.jpg" width="142" height="109" alt="Google App Engine Logo" style="float:right"/> Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

Page 39: Hypertext Markup Language HTML Chapter 2

<h1> <img src="appengine.jpg" width="142" height="109" alt="Google App Engine Logo" /> Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

<h1> <img src="appengine.jpg" width="142" height="109" alt="Google App Engine Logo" style="float:right"/> Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p>

Page 40: Hypertext Markup Language HTML Chapter 2

HTML Document Structure

Page 41: Hypertext Markup Language HTML Chapter 2

Well-Formed HTML Documents

• Browsers need to know what contract you are agreeing to (doctype)

• We need a section for meta-data about the HTML document (head)

• And then the displayable content of the HTML document (body)

Page 42: Hypertext Markup Language HTML Chapter 2

Outline of an HTML Document<!DOCTYPE ><html> <head> meta-data.... </head> <body> Page content.... </body></html>

Contract about the HTML style used

the page.

Metadata about the page.

Displayable content of the page.

Page 43: Hypertext Markup Language HTML Chapter 2

Outline of an HTML Document<!DOCTYPE ><html> <head> meta-data.... </head> <body> Page content.... </body></html>

Contract about the HTML style used

the page.

Metadata about the page.

Displayable content of the page.

Page 44: Hypertext Markup Language HTML Chapter 2

A Simple but Modern Page<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Learning the Google App Engine</title> </head> <body> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p> </body></html>

Page 45: Hypertext Markup Language HTML Chapter 2

Browsers: Lost in Transition

• Between 1995 and 2003 browsers were different - often on purpose to attempt to make their market share “sticky”

• At some point we knew there needed to be a future where all browsers did *exactly* the same thing based on CSS and HTML standards

• How to get from “here” to “there” - no one could “win”

Page 46: Hypertext Markup Language HTML Chapter 2

1993 SIMPLE UGLY HTML

HTML+Proprietary Extensions

HTML+Proprietary Extensions

HTML+Proprietary Extensions

StandardCSS andHTML

How do we let browsers continue their evil ways while

transitioning to standards?

1999

2008

Page 47: Hypertext Markup Language HTML Chapter 2

StandardMode

QuirksMode HTML+

Proprietary Extensions

HTML+Proprietary Extensions

HTML+Proprietary Extensions

StandardCSS andHTML

Inconsistencyis OK

Web developers and browsers are expected

to be “perfect.” Responsibility goes

both ways.

1993 SIMPLE UGLY HTML

1999

2008

Page 48: Hypertext Markup Language HTML Chapter 2

www.w3schools.com/browsers/browsers_stats.asp

Designing for the Browsers out there...

Page 49: Hypertext Markup Language HTML Chapter 2

You get to make a choice...

• (a) Do you want to be lazy and sloppy and hope that your pages look good across multiple browsers and multiple versions of the same browsers

• (b) Do you want to be professional and have your pages to render identically across all browsers?

• If you choose (b) - you take on some additional responsibility.

Page 50: Hypertext Markup Language HTML Chapter 2

DOCTYPE: Indicating your Choice

• Browsers look at the first line of your HTML file to see is you have agreed to comply to HTML standards

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Learning the Google App Engine</title> </head> <body> <h1>Google App Engine: About</h1>

Page 51: Hypertext Markup Language HTML Chapter 2

Which DOCTYPE?

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

http://www.webmasterworld.com/html/3061635.htm

Page 52: Hypertext Markup Language HTML Chapter 2

Which DOCTYPE?

• Easy to start a fight - just Google “what is the best doctype”

• Loose - legacy

• Transitional - Mix of Developers

• Strict - New Project which can enforce rules from the start

• http://www.webmasterworld.com/html/3061635.htm (and others)

Page 53: Hypertext Markup Language HTML Chapter 2

Well-Formed HTML Documents

• Browsers need to know what contract you are agreeing to (doctype)

• We need a section for meta-data about the HTML document

• And then the displayable content of the HTML document

Page 54: Hypertext Markup Language HTML Chapter 2

A Valid Web Document<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Learning the Google App Engine</title> </head> <body> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p> </body></html>

Page 55: Hypertext Markup Language HTML Chapter 2

A Valid Web Document<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Learning the Google App Engine</title> </head> <body> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p> </body></html>

Contract about the HTML style used

the page.

Metadata about the page.

Displayable content of the page.

Page 56: Hypertext Markup Language HTML Chapter 2

Checking Validity

• We can check to see if a page “meets the rules” - does it live up to its doctype?

• http://validator.w3.org

• Enter, HTML, upload a file, or enter a web-accessible URL

Page 57: Hypertext Markup Language HTML Chapter 2

SuccessLess-than-successful

Note: When the validator fails, only look at the first message and fix that - and then re-run. One simple error will often

cascade into 30-40 “The validator is lost and confused

errors”.

Page 58: Hypertext Markup Language HTML Chapter 2

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Learning the Google App Engine</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > </head> <body> <h1>Google App Engine: About</h1> <p> Welcome to the site dedicated to learning the Google Application Engine. We hope you find www.appenginelearn.com useful. </p> </body></html>

To fix the warning - we add a header to indicate the character set of our

document.

Page 59: Hypertext Markup Language HTML Chapter 2

<HTML><HEAD> <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Win"> <TITLE>dr-chuck.com </TITLE></HEAD><BODY BGCOLOR="#000000" LINK="#AAAAAA" VLINK="#AAAAAA" ALINK="#AAAAAA"><table Border=0><tr>...

Page 60: Hypertext Markup Language HTML Chapter 2

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>University of Michigan</title>....

Page 61: Hypertext Markup Language HTML Chapter 2

Summary

• HTML has gone through many changes and evolutions

• It started clean and simple - then got ugly and nasty - now we are back to a clean and simple approach

• HTML Markup needs to focus on meaning - not formatting

• Formatting is handled using CSS - Cascading Style Sheets