Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf ·...

35
Chapter 4: Marking Up With HTML: A H t tM k L Pi Hypertext Markup Language Primer Fluency with Information Technology Third Edition by Lawrence Snyder Lawrence Snyder Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Transcript of Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf ·...

Page 1: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Chapter 4: Marking Up With HTML: A H t t M k L P iHypertext Markup Language Primer

Fluency with Information TechnologyThird Edition

by Lawrence SnyderLawrence Snyder

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Page 2: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Marking Up with HTML

• Tags describe how a web page should lookTags describe how a web page should look

• Formatting with Tags:W d bb i ti l d i l b k t < >– Words or abbreviations enclosed in angle brackets < >

– Come in pairs (beginning and end):• <title> </title>• <title> </title>

– Tags are not case-sensitive, but the actual text between the tags isg

1-2

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-2

Page 3: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Tags for Bold, Italic, and underline• Bold: <b> </b>

• Italic: <i> </i>Italic: i /i

• Underline: <u> </u>– Tag pair surrounds the text to be formatted

• You can apply more than one kind of formatting at a time

• <b><i>Veni, Vidi, Vici!</i></b> produces: Veni, Vidi, Vici!– Tags can be in any order, but have to be nested correctly

• Some tags do not surround anything, so they don't have an ending form. Closing angle bracket is replaced by />– <hr /> inserts a horizontal rule (line)

1-3

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-3

( )– <br /> inserts a line break

Page 4: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

An HTML Web Page FileBegins with <html> and ends with </html>

<html><head>

Preliminary material goes here, including<title> … </title>

</head></head><body>

Main content of the page goes hereMain content of the page goes here</body>

</html>1-4

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-4

</html>

Page 5: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Structuring Documents

• Markup language describes how a document's p g gparts fit together

• Headings:g– Choice of eight levels of heading tags to produce

headings, subheadings, etc.– Headings display material in large font on a new line<h1>Pope</h1> <h2>Cardinal</h2> <h3>Archbishop</h3>produces:

PopeCardinal Archbishop

1-5

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-5

Page 6: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-6

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-6

Page 7: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

HTML Format vs. Display Format

• HTML text was run together on one line, but gdisplayed formatted on separate lines

• HTML source tells the browser how to produce th f tt d i b d th i fthe formatted image based on the meaning of the tags, not on how the source instructions look

• But HTML is usually written in a structured• But HTML is usually written in a structured (indented) form to make it easier for people to understand<h1>Pope</h1>

<h2>Cardinal</h2><h3>Archbishop</h3>

1-7

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-7

<h3>Archbishop</h3>

Page 8: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

White Space

• White space that has been inserted for readabilityWhite space that has been inserted for readability– Spaces– Tabs– New lines

• Browser turns any sequence of white space y q pcharacters into a single space before processing HTML– Exception: Preformatted information between

<pre> and </pre> tags is displayed as it appears

1-8

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-8

Page 9: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-9

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-9

Page 10: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-10

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-10

Page 11: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Brackets in HTML: The Escape Symbol

• What if our web page needed to show a math p grelationship like

0 < p > r

• The browser would interpret < p > as a paragraph tag, and would not display it

• To show angle brackets, use escape symbol —ampersand (&) — then an abbreviation, then a semicolon (;)semicolon (;)

&lt; displays as <&gt; displays as >& di l &

1-11

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-11

&amp; displays as &

Page 12: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Special Characters

• &lt; <

• &gt; >

• &amp; &p;

• &nbsp; (non-breaking space)

• &mdash – (em dash)&mdash (em dash)

• Full list at• Full list at

http://www.w3.org/TR/REC-html40/sgml/entities.html

1-12

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-12

Page 13: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Accent Marks in HTML

• Letters with accent marks use the escape symbolLetters with accent marks use the escape symbol

• Ampersand, then letter, then the name of the accent mark then semicolonaccent mark, then semicolon

&eacute; displays as é&ntilde; displays as ñ

• Full list at

htt // 3 /TR/REC ht l40/ l/ titi ht lhttp://www.w3.org/TR/REC-html40/sgml/entities.html

1-13

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-13

Page 14: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-14

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-14

Page 15: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Attributes in HTML

• Properties such as text alignment require more informationinformation

• For justification, we need to specify left, right, or center

• Attributes appear inside the angle brackets of start tag, after tag word, with equal sign, value in double quotes Do not use “fancy/smart quotes!!!”quotes. Do not use fancy/smart quotes!!!

<p align = "center">(default justification is left)

• Horizontal rule attributes: width and size (thickness) can be specified or left to default

<hr width="50%" size="3" />1-15

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-15

<hr width= 50% size= 3 />

Page 16: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Marking Links With Anchor Tags

• There are two sides of a hyperlink:1. Anchor text (the text in the current document that is highlighted)2. Hyperlink reference (the address of a Web page / target of the

link)

• Begin with <a followed by a space• Give the link reference using href="filename"• Close the start anchor tag with >Close the start anchor tag with • Text to be displayed for this link• End anchor tag with </a>

<a href="target_of_the_hyperlink">Anchor Text Seen</a>Anchor Text Seen

1-16

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-16

Page 17: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Anchor Tags (cont'd)

• Absolute pathnames: Reference pages atAbsolute pathnames: Reference pages at other web sites using complete URLs

htt // /di t th/filhttp://server/directory_path/filename

<a href="http://www aw com/snyder/index html">FIT</a><a href="http://www.aw.com/snyder/index.html">FIT</a>

1-17

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-17

Page 18: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Anchor Tags (cont'd)

• Relative pathnames: Reference pages stored to p p gthe same directory (give only the name of the file)

Read <a href=" /filename">this file</a>Read <a href= ./filename >this file</a>.– Relative pathnames are more flexible — we can move

web files around as a group– Relative pathnames can also specify a path deeper or

higher in the directory structure/di t /fil /di t /fil./directory/filename ../directory/filename

. Current directoryP t di t ( l l )

1-18

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-18

.. Parent directory (one level up)

Page 19: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-19

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-19

Page 20: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Including Pictures With Image Tags

• Image Tag Format: g g<img src="filename" />– src short for sourcesrc short for source– Absolute and relative pathname rules apply

• Pictures can be used as links using• Pictures can be used as links using anchor tag<a href="fullsize jpg"><img src="thumbnail jpg" /></a><a href= fullsize.jpg ><img src= thumbnail.jpg /></a>

1-20

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-20

Page 21: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Including Pictures With Image Tags

• GIF and JPEG Imagesg– GIF: Graphic Interchange Format

• 8 bits (256 colors or levels of gray)8 bits (256 colors or levels of gray)

– JPEG: Joint Photographic Experts Group• 24 bits (millions of colors – full color; levels of24 bits (millions of colors full color; levels of

compression)

– Tell browser which format image is in using g gfilename extension (.gif, .jpg or .jpeg)

1-21

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-21

Page 22: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Positioning the Image in the Document

• By default, images are inserted in the page at the point h th t i ifi d i th HTML d th t t liwhere the tag is specified in the HTML, and the text lines

up with the bottom of the image• Align attribute can line up image with top of line of text, g p g p ,

middle, or bottom• Align left, center, or right attribute puts the image on the

side of the browser window — text flows around itside of the browser window — text flows around it• To put image on separate line, enclose within paragraph

tags• Can specify how large the image should be displayed (in

pixels) with height and width attributes

1-22

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-22

Page 23: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Handling Color

• Color is used for both background and textColor is used for both background and text

• bgcolor attribute of body tag gives solid background colorbackground color– Use hexadecimal color numbers (0-9 A-F)

<body bgcolor="#FF00FF"> (magenta)y g ( g )

– Or use predefined color terms<body bgcolor="magenta">

• color attribute can be used with body text, link, or font tags

1-23

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-23

g<font color="red">text</font>

Page 24: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-24

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-24

Page 25: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-25

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-25

Page 26: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-26

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-26

Page 27: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Handling Lists

• Unnumbered (bulleted) list:( )– <ul> and </ul> tags begin and end the list– <li> and </il> tags begin and end the items within the list

O d d ( b d) li t• Ordered (numbered) list:– <ol> and </ol> tags begin and end the list– Uses the same <li> tagsg

• Sublists: Insert lists within lists (between <li> </li> tags)

• Definitional list:Definitional list: – <dl> and </dl> tags begin and end the list– <dt> and </dt> surround the terms to be defined

<dd> d </dd> d th d fi iti (i d t d)1-27

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-27

– <dd> and </dd> surround the definitions (indented)

Page 28: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Handling Tables

• Tables begin and end with <table> and </table> tagsg g

• Rows are enclosed in table row tags, <tr> and </tr>

• Cells of each row are surrounded by table data tags, y g ,<td> and </td>

• Create a caption centered at the top of the table with ti d / ti t<caption> and </caption> tags

• Column headings are created as first row of table by using <th> and </th> tags instead of table data tagsusing <th> and </th> tags instead of table data tags

• See examples in textbook

1-28

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-28

Page 29: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

Controlling Text with Tables

• Tables can control arrangement of information gon a page

• e.g., a series of links listed across the top of the g , ppage could be placed in a one-row table to keep them together– If the window is too small to display all the links, table

keeps them in a row and a scroll bar is added– If the tags are not in a table, the links will wrap to theIf the tags are not in a table, the links will wrap to the

next line instead

1-29

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-29

Page 30: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-30

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-30

Page 31: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-31

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-31

Page 32: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-32

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-32

Page 33: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-33

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-33

Page 34: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-34

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-34

Page 35: Chapter 4: Marking Up With HTML: A HttMkL PiHypertext Markup …marvin/cs103/lectures/ch04.pdf · 2009. 9. 11. · Tags for Bold, Italic, and underline • Bold:

1-35

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-35