HTML and JavaScript
for Visual Learners
1810 Monument Avenue, Suite 100
Richmond, VA 23220
www.visibooks.com
HTML and JavaScript for Visual Learners
Published by Visibooks, LLC, Richmond, VA
Copyright
You have permission to post this book on a Web site, e-mail it, print it,
or pass it along for free to anyone you like, as long as you make no
changes or edits to its contents or digital format. Make as many copies
as you want. However, the right to sell this book, whether in digital or
bound form, is strictly reserved to Visibooks, LLC.
Suggestions
If you have a suggestion on how to improve this book, send it to
[email protected] . If we use it, well send you a complete set
of all published Visibooks and post your name in the Acknowledgements of
the next edition.
Trademarks and Disclaimer
Visibooks is a trademark of Visibooks, LLC. All brand and product names in
this book are trademarks or registered trademarks of their respective companies.
Visibooks makes every effort to ensure that the information in this book is
accurate. However, Visibooks makes no warranty, expressed or implied, with
respect to the accuracy, quality, reliability, or freedom from error of this
document or the products described in it. Visibooks makes no representation or
warranty with respect to this books contents, and specifically disclaims any
implied warranties or fitness for any particular purpose. Visibooks disclaims all
liability for any direct, indirect, consequential, incidental, exemplary, or special
damages resulting from the use of the information in this document or from the
use of any products described in it. Mention of any product does not constitute an
endorsement of that product by Visibooks. Data used in examples are intended
to be fictional. Any resemblance to real companies, people, or organizations is
entirely coincidental.
International Standard Book Number: 0-9707479-2-6
First Edition
Table of Contents
Introduction ............................................................................................... 1
HTML Basics.................................................................... 3
Create a home page.............................................................................. 4
Create the home page......................................................................................................4
View the page in a browser ............................................................................................11
Format pages and text.........................................................................14
Change fonts................................................................................................................... 14
Change text size.............................................................................................................16
Change text weight ........................................................................................................ 17
Change text color ...........................................................................................................18
Align text.........................................................................................................................19
Indent text.......................................................................................................................21
Create lists ......................................................................................................................23
Create links to new pages................................................................... 25
Step 1: Create a new page .............................................................................................25
Step 2: Link to the new page........................................................................................ 28
Create e-mail and external links.......................................................... 31
Create an e-mail link...................................................................................................... 31
Link to an external site ..................................................................................................33
Insert and align graphics.................................................................... 34
Capture a graphic from the Web ...................................................................................34
Insert a graphic...............................................................................................................36
Align a graphic................................................................................................................38
Format a graphic............................................................................................................. 41
Create a basic navigation system........................................................ 44
Link back to the home page ..........................................................................................44
Link pages to each other ...............................................................................................45
Use graphics as links.....................................................................................................46
Use graphics as links.....................................................................................................47
Change page, link colors .................................................................... 50
Change background color of page ................................................................................50
Change link colors .......................................................................................................... 51
Change link colors ..........................................................................................................52
Download other Visibooks for free at www.visibooks.com
Layout & Navigation ...................................................... 57
Lay out pages using tables ................................................................. 58
Create a table................................................................................................................. 58
Create a table................................................................................................................. 59
Format a table ................................................................................................................ 63
Create a table-based home page ................................................................................. 67
Create new table-based pages......................................................................................73
Create navigation bars........................................................................ 76
Create a navigation bar for a home page .................................................................... 76
Create a navigation bar for a main section page ........................................................ 79
Add subsections to site ......................................................................82
Insert a table for content and subsection links ..........................................................82
Create subsection pages............................................................................................... 84
Place tables within tables...................................................................88
Link to an external site using frames................................................... 91
Interactivity...................................................................99
Insert META tags.............................................................................. 100
Create forms .................................................................................... 102
Use style sheets................................................................................ 111
Create a style sheet......................................................................................................112
Apply a style sheet....................................................................................................... 114
Create link effects with style sheets........................................................................... 117
Upload sites to a Web server..............................................................121
Advanced Layout.......................................................... 131
Employ background graphics............................................................ 132
Employ spacer GIFs ...........................................................................135
Insert a horizontal rule......................................................................137
Specify page margins....................................................................... 138
Download other Visibooks for free at www.visibooks.com
Practical JavaScript ...................................................... 141
Enable rollover graphics ....................................................................142
View source code.......................................................................................................... 143
Copy source code ......................................................................................................... 144
Modify source code......................................................................................................146
Open new windows ...........................................................................150
Validate form input............................................................................153
Validate form input............................................................................154
See how it works .......................................................................................................... 154
Insert the validation script.......................................................................................... 155
Modify the <FORM> tag.................................................................................................156
Additional Resources .............................................................................. 157
HTML Tag Chart .......................................................................................159
Index.......................................................................................................165
Download other Visibooks for free at www.visibooks.com
Download other Visibooks for free at www.visibooks.com
1
Introduction
Welcome to HTML and JavaScript for Visual Learners. If youve never
used a Visibook before, youll find that it contains several hundred
illustrations, with comparatively little text. It presents essential tasks,
breaks them down into steps, then walks you through them with
illustrations.
What youll learn
Youll learn how to use HTML to create a
solid, attractive Web site thats easy to
navigate. Youll also learn how to upload
it to a Web server.
You wont become an expert in Web
publishingthat takes practice and real-
world experience. But you will learn the
fundamentals of site-building, and get a
good foundation on which to build
professional-level skills.
Additional resources for acquiring expert-
level HTML and JavaScript skills are Follow the steps
found at the end of this book.
!
How youll learn it
This book has five sections: HTML Basics,
Layout & Navigation, Interactivity,
Advanced Layout, and Practical
JavaScript.
At the end of each task and section are See the results
practice exercises. Dont worry if you
cant work through the whole book in a
day or two. Take your time, and try to do the practice. You can check
your work against examples posted on the Web.
Download other Visibooks for free at www.visibooks.com
2
Before you begin
Before you begin, its important that you know Windows well. A
working knowledge of Windows makes it much easier to learn HTML
and JavaScript. You should be familiar with:
• How directories work
• Windows Explorer
• Basic word processing
Make sure you can perform the following tasks:
• Create a folder on your computers hard drive
• Create a folder within a folder
• Copy a paragraph from one document and paste it into another.
If you have trouble doing this, set
aside a couple of hours to learn
Windows basics. Have a friend or
co-worker who is proficient with
computers walk you through
Windows Explorer, creating folders
and becoming familiar with file
extensions.
You should also practice using the
Cut, Copy, and Paste commands in
a standard word processing
program. When you can do these
things on your own, youre ready to
learn HTML and JavaScript.
Download other Visibooks for free at www.visibooks.com
3
HTML Basics
In this section, youll learn how to:
• Create a home page
• Format text
• Create links to new pages
• Create e-mail and external links
• Insert graphics
• Create a navigation system
• Change page and link colors
Youll build a site that looks like this:
Download other Visibooks for free at www.visibooks.com
4
Create a home page
Create the home page
1. Open a browser, such as Internet Explorer or Netscape Navigator.
2. Open the program Notepad. Do this by first clicking the
button on the taskbar, then Programs, then Accessories, then
Notepad.
3. At the top of the Notepad screen, type:
<HTML>
Tip:<HTML> is a tag. Tags are instructions to a Web browser. This
particular instruction lets the Web browser know that what follows is
a Web page, written in HTML.
Tags can be written in upper-case or lower-case lettersit doesnt
matter which. <HTML>, <html>, or <HtMl> are all fine.
Download other Visibooks for free at www.visibooks.com
5
4. Save the file.
5. When the Save As window appears, select the C:\ drive in the
Save in drop-down list.
6. Create a new folder by clicking on the icon.
Download other Visibooks for free at www.visibooks.com
6
7. Name the new folder Dogs, then double-click it so it appears in
the Save in box.
8. In the File name textbox, type index.html.
9. In the Save as type drop-down list, select All Files. When youre
done, the window should look like this:
Download other Visibooks for free at www.visibooks.com
7
10. Save the page by clicking on the Save button.
Home page file names
All Web pages have a .html extension (or .htm).
All home pages have the file name index.html. index.html
comes up automatically when the address of a domain or
directory where its located is typed into a browser.
For instance, if you go to www.visibooks.com, the home page
appears automatically. Thats because its file name is
index.html. If the file name of the Visibooks home page was
homepage.html, youd have to type
www.visibooks.com/homepage.html to get it to appear.
The Microsoft exception: To get your home page to come up
automatically on a Web server running Microsofts Internet
Information Server as its operating system, give your home
page the file name default.htm.
11. Below the <HTML> tag, type:
<HEAD>
<!--Created by Your Name-->
</HEAD>
Tip: The <HEAD> section contains information that doesnt show up
on the page when it is viewed in a browser. Note the closing
</HEAD> tag: in HTML, you must give the browser instructions to
end something as well as start it.
Download other Visibooks for free at www.visibooks.com
8
Tip: <!--Created by Your Name--> is called a comment.
Whatever text is between the dashes wont show up on a browsers
screenits only visible if someone views the pages HTML code. You
need to include the ! for this to work.
12. Below the </HEAD> tag, title the page A Home Page About
Dogs by using <TITLE> tags:
<TITLE>
A Home Page About Dogs
</TITLE>
Tip: Note that the text A Home Page About Dogs is not a tag. It is
text surrounded by tags. The <TITLE> tags tell the browser what to
do with the text: make it the title of the page.
Download other Visibooks for free at www.visibooks.com
9
Page titles
The title of a Web page describes the page. Its what appears in
a browsers History list. The title also shows up as a link when a
page comes up in a search engine. If all your pages have
discrete, descriptive titles, theyll be easier for people to find.
The page title shows up in the top, or title, bar of the browser
used to view it. The title of this page is Dogs.
13. Below the </TITLE> tag, add:
<BODY>
</BODY>
Tip: Anything you want to be visible in a browsers main window,
put between the <BODY> and </BODY> tags.
Download other Visibooks for free at www.visibooks.com
10
14. Below the </BODY> tag, close the </HTML> tag. When youre
finished, the code should look like this:
15. Between the <BODY> and </BODY> tags, type the words:
Dogs Home Page
16. Save the page.
Download other Visibooks for free at www.visibooks.com
11
View the page in a browser
1. Go to the browser and on its menu bar, click File, then Open.
Tip: If youre using Netscape Communicator instead of Internet
Explorer, click Open Page, then Choose File.
2. When the Open window appears, click the Browse button.
Download other Visibooks for free at www.visibooks.com
12
3. When the new window appears, navigate to the Dogs folder in the
Look in drop-down list, then select the home page: index.html.
4. Click the Open button, then the OK button. The page should
come up in the browser and look like this:
You have created a home page titled “A Home Page About
Dogs.”
The home pages file name is index.html.
It is located in a folder called Dogs on the C:\ drive.
Download other Visibooks for free at www.visibooks.com
13
Practice: Create a home page
A. What is the correct file name for a home page?
B. Why is there a special file name for home pages?
C. Why is it important that the home pageand all other pages in a
Web sitehave accurate titles?
D. What is the difference between a pages title and its file name?
Answers
A. index .html
B. It allo ws ho me pages to appear in a bro wser witho ut typing the file name as part o f a Web address.
C. Accurate titles allo w peo ple to find pages easier when bo o k mark ing them o r searching in a bro wsers H isto ry list.
D. A page title appears in the T itle bar at the to p o f the bro wser. Its plain tex t, such as T he Smith Family: Vacatio n
Pictures, that mak es it easy fo r peo ple to k eep track o f a page. A pages file name, such as vacpics.html, is ho w the
co mputer k eeps track o f it.
Download other Visibooks for free at www.visibooks.com
14
Format pages and text
Change fonts
1. In front of the words Dogs Home Page, insert a <FONT> tag
with the attribute FACE=”arial”:
<FONT FACE=”arial”>Dogs Home Page</FONT>
2. After the words, close the <FONT> tag:
<FONT FACE=”arial”>Dogs Home Page</FONT>
Tip:Think of an attribute as a sub-instruction to the browser. In this
case, the <FONT> tag tells the browser that text will be changed, and
the FACE attribute tells it how to change, specifying the Arial
typeface.
Download other Visibooks for free at www.visibooks.com
15
3. View the page in the browser. Click the browsers Refresh button,
and the page should look like this:
Text is in the
Arial font
Web fonts
When text is viewed on a computer, only fonts installed on the
computer can be seen. For instance, if someone created a page
that specified the Tekton font, almost no one viewing it would
see it in Tekton because very few computers have that font
installed. Computers without Tekton would display text in the
default font: Times New Roman.
All Windows computers have the Arial font installed.
Windows 95 and later computers have Verdana. Macintoshes
have Helvetica, the font that Arial is based upon.
To cover all bases, specify multiple fonts:
<FONT FACE=”verdana,arial,helvetica”>
Tip: If a page doesnt look like its supposed toor nothing shows up
at allcheck the HTML code youve written. You might have left out
a quote or made some other small mistake. Something that seems
insignificant can wreck a page:
<FONT FACE=”arial>
Missing end quote ()
Download other Visibooks for free at www.visibooks.com
16
Change text size
1. In Notepad, add the SIZE=”+4” attribute to the <FONT> tag:
<FONT FACE=”arial” SIZE=”+4”>Dogs Home
Page</FONT>
2. Save the page and view it in the browser. It should look like this:
Download other Visibooks for free at www.visibooks.com
17
Change text weight
1. In Notepad, add the <B> tag in front of the words Dogs Home
Page and close it after them:
<FONT FACE=”arial” SIZE=”+4”><B>Dogs Home
Page</B></FONT>
Tip: Wheninserting multiple tags, arrange them in mirror-image
order. The tags and text above are a good example: since it starts with
the <FONT> tag, it ends with the </FONT> tag. Tags that arent
arranged in mirror-image order can cause display problems in some
browsers.
2. Save the page and view it in the browser. It should look like this:
Download other Visibooks for free at www.visibooks.com
18
Change text color
1. In the <FONT> tag, add the attribute COLOR=”red”:
<FONT FACE=”arial” SIZE=”+4” COLOR=”red”>
2. Save the page. View it in the browser, and the text should show up
red.
3. Change the text color to black, then save the page.
<FONT FACE=”arial” SIZE=”+4” COLOR=”black”>
Download other Visibooks for free at www.visibooks.com
19
Align text
1. Beneath the present text and tags, insert a <P> tag to begin a new
paragraph.
2. Beneath the <P> tag, insert the tag <FONT FACE=”arial”
SIZE=”-1”> and the words “These are my favorite
breeds of dog:”
3. Within the <P> tag, add the attribute ALIGN=”right”:
<P ALIGN=”right”>
4. Add a closing </P> tag after the new paragraph.
<P ALIGN=”right”>
<FONT FACE=”arial” SIZE=”-1”>These are my
favorite breeds of dog:
</P>
Download other Visibooks for free at www.visibooks.com
20
Tip: Usually a <P> tag requires no closing </P> tag in HTML, but
in this case the ALIGN=”right” attribute is used. The closing
</P> tag after the paragraph keeps the browser from right-aligning
whatever is beneath it.
5. Save the page, then view it in the browser. It should look like this:
6. Remove the ALIGN=”right” attribute from the <P> tag.
Tip: To generate a single-line break rather than the double-space a
<P> tag generates, use the <BR> tag. Putting a <BR> or Break tag
between two lines of text will bump the second line down to the next
line:
<FONT FACE=”arial” SIZE=”+4”><B>Dogs Home
Page</B></FONT>
<BR>
<FONT FACE=”arial” SIZE=”-1”>These are my
favorite breeds of dog:
Download other Visibooks for free at www.visibooks.com
21
Indent text
1. Below the text, These are my favorite breeds of dog:, insert three
new paragraphs:
<P>Chesapeake Bay Retriever</P>
<P>German Shepherd</P>
<P>Yorkshire Terrier</P>
2. Enclose these paragraphs in Unordered List tags to indent them:
<UL>
<P>Chesapeake Bay Retriever</P>
<P>German Shepherd</P>
<P>Yorkshire Terrier</P>
</UL>
Download other Visibooks for free at www.visibooks.com
22
3. Save the page and view it in the browser. It should look like this:
Tip: Notice how all the text below the <FONT FACE=”arial”
SIZE=”-1”> tag looks the same. It will stay that way until the
closing </FONT> tag is inserted.
Download other Visibooks for free at www.visibooks.com
23
Create lists
1. With the three breeds of dog, replace the <P> and </P> tags with
<LI> tags to generate bullets in front of the text that follows:
<UL>
<LI>Chesapeake Bay Retriever
<LI>German Shepherd
<LI>Yorkshire Terrier
</UL>
2. Save the page and view it in the browser. It should look like this:
Download other Visibooks for free at www.visibooks.com
24
Practice: Format pages and text
A. Why are the most common font choices Arial, Verdana, and
Helvetica?
B. What kinds of computers have the font Arial installed? Which have
Helvetica instead?
1. Change the title of the home page to My Favorite Dogs.
2. Change the bulleted list to a numbered list.
Tip: Use <OL> instead of <UL> to generate a numbered list.
3. Change the numbered list back to a bulleted list.
4. Make the list items bold. When you view it in the browser, the page
should look like this:
Answers
A. T ho se are the fo nts that mo st Windo ws co mputers have installed.
B. Windo ws co mputers have Arial, M acs have H elvetica.
Download other Visibooks for free at www.visibooks.com
25
Create links to new pages
Step 1: Create a new page
1. In Notepad, change the title of the page to Chesapeake Bay
Retrievers, then take out all the tags and text between the
<BODY> and </BODY> tags.
2. On the menu bar, click File, then Save As.
3. Save the new page with the file name chesapeake.html.
Tip: Remember to Save as type: All Files.
Download other Visibooks for free at www.visibooks.com
26
File names for the Web
Most Web servers are Unix- or Linux-based, which dont deal
cleanly with spaces in file names. For instance if you name a
file fido page.html, it may show up in the URL box of the
browser as fido%20page.html.
Also, Web servers are case-sensitive, so keeping file names
lower-case eliminates a potential source of mistakes.
Make all file names in a Web sitepages, graphics and
folderslower-case, with no spaces.
Correct file name: german.html
Incorrect: German Shepherds.html
4. Beneath the <BODY> tag, type Chesapeake Bay Retrievers. This is
the page heading. Make it verdana, bold, size +3:
<BODY>
<FONT FACE=”verdana” SIZE=”+3”><B>Chesapeake
Bay Retrievers</B></FONT>
</BODY>
Download other Visibooks for free at www.visibooks.com
27
5. Save the page.
Providing navigation clues with text size
The heading of the Chesapeake Bay Retriever page is made one
size smaller than the heading of the home page. Thats because
the CBR page is one step down in the site hierarchy.
Level 1: Dogs
(top level heading; SIZE=”+4”) Dogs
Level 2: Chesapeake Bay Retrievers
(second-level heading; SIZE=”+3”) Chesapeake Bay
Retrievers
Making the heading of the CBR page smaller than the home
pages heading helps show people where they are in the site.
Download other Visibooks for free at www.visibooks.com
28
Step 2: Link to the new page
1. Open the home page (index.html) in Notepad. In front of the first
item, Chesapeake Bay Retriever, insert an anchor tag.
Then close the anchor tag :
<LI><B><A HREF=”chesapeake.html”>Chesapeake
Bay Retriever</A></B>
How an anchor tag works
Anchor tags create a clickable link to another page.
A page with this file name
is linked to these words.
<a href=”filename.html”>New Page</a>
Download other Visibooks for free at www.visibooks.com
29
2. Save the home page and view it in the browser. The words
Chesapeake Bay Retriever should be a link, and the page
should look like this:
3. Click on the Chesapeake Bay Retriever link. The Chesapeake
Bay Retriever page should appear in the browser.
Download other Visibooks for free at www.visibooks.com
30
Practice: Create links to new pages
A. Why should file names be lower-case and free of spaces?
B. Why should the headings on section pages (Chesapeake Bay
Retrievers, German Shepherds) be smaller than the heading of the
home page?
1. Create new pages for German Shepherds and Yorkshire Terriers.
Page Title File Name
German Shepherds German Shepherds german.html
Yorkshire Terriers Yorkshire Terriers yorkshire.html
2. On the home page, link the words German Shepherd and
Yorkshire Terrier to their pages.
3. On the home page, remove the words Home Page after
Dogs.
4. On the Chesapeake Bay Retriever, German Shepherd and Yorkshire
Terrier pages, put the page headings in the same font and weight as
the home page (Verdana; bold).
5. Make the page headings of these pages one size smaller than the
heading on the home page, just like on the Chesapeake Bay
Retriever page.
6. Save all pages and click on the home pages links to make sure they
work.
Answers
A. B ecause mo st Web servers deal better with lo wer-case, spaceless file names.
B. It pro vides site users with a visual distinctio n between first-level (ho me) pages and seco nd-level (main sectio n) pages.
Download other Visibooks for free at www.visibooks.com
31
Create e-mail and external links
Create an e-mail link
1. In a new paragraph beneath the list, type the sentence For more
information, contact
[email protected].
2. Surround the e-mail address with anchor tags, but instead of
linking it to a Web page, use the mailto command to link it to an
e-mail program:
For more information, contact
<A HREF=”mailto:
[email protected]”>
[email protected]</A>
Download other Visibooks for free at www.visibooks.com
32
3. Save the page. When you view it in the browser, it should look like
this:
How e-mail links work
When someone goes to a Web site and clicks on an e-mail link,
its supposed to open the e-mail program on that persons
computer and insert the address into a new message.
If the persons e-mail program isnt configured correctly, this
wont work. Thats why e-mail links should use the e-mail
address as a link: so people can enter the address manually if
they have to.
Download other Visibooks for free at www.visibooks.com
33
Link to an external site
1. In Notepad, add a new sentence after the last one. Type the
sentence, Please also visit www.dogs.com.
2. Surround the Web address www.dogs.com with these anchor
tags to link it to the external Web site:
<A
HREF=”http://www.dogs.com”>www.dogs.com</A>
Tip: For an external link to work, you must type http:// as part of
the Web address.
3. Save the page.
4. Preview the page in the browser, then click on the link to see if it
links to the external site www.dogs.com.
5. Close the browser.
Download other Visibooks for free at www.visibooks.com
34
Insert and align graphics
Capture a graphic from the Web
1. Open a new browser window.
2. Go to the Web site www.visibooks.com/dogpics.
3. Place your cursor on top of the picture of the Chesapeake Bay
Retriever, then click with your right mouse button.
Right mouse
button
Download other Visibooks for free at www.visibooks.com
35
4. Click Save Picture As.
5. When the Save Picture window appears, select the “Dogs” folder
in the Save in drop-down list.
6. Create a new folder within Dogs called graphics.
7. Double-click on the graphics folder so it appears in the Save in
drop-down list.
8. Click the Save button to save the graphic inside the graphics
folder.
Tip: Creating this separate sub-folder to hold your sites graphics
makes the site easier to organize and update.
Download other Visibooks for free at www.visibooks.com
36
Insert a graphic
1. In Notepad, open the Chesapeake Bay Retriever page, file name
chesapeake.html.
2. Create a new paragraph under the main heading.
3. In the new paragraph, insert an image tag:
<IMG SRC=”graphics/chessie.gif”>
folder graphic
Tip: Notice that in this image tag theres a path. For the image
source, the tag first points to the graphics folder, then to the file name
of the image within it.
Download other Visibooks for free at www.visibooks.com
37
4. Save the page, then view it in the browser. It should now look like
this:
Download other Visibooks for free at www.visibooks.com
38
Align a graphic
1. In a new paragraph below the graphic, type in:
Chesapeake Bay Retrievers love water. If you
throw tennis balls in the water, these dogs
will chase them and bring them back until
your arm falls off.
Download other Visibooks for free at www.visibooks.com
39
2. Save the page and view it in the browser. The page should look like
this:
3. Go back to Notepad and add the ALIGN=”left” attribute to the
<IMG> tag:
<IMG SRC=”graphics/chessie.gif”
ALIGN=”left”>
Download other Visibooks for free at www.visibooks.com
40
4. Save the page and view it in the browser (just click the Refresh
or Reload button). It should look like this:
Download other Visibooks for free at www.visibooks.com
41
Format a graphic
1. In the Chesapeake Bay Retriever page, add this ALT attribute to the
<IMG> tag:
<IMG SRC=”graphics/chessie.gif” ALIGN=”left”
ALT=”Chesapeake Bay Retriever”>
Alt text allows visually-impaired people to know what a
graphic represents. Alt text also allows search engines to index
visual content.
2. Add the VSPACE=”4” and HSPACE=”12” attributes as well:
<IMG SRC=”graphics/chessie.gif” ALIGN=”left”
ALT=”Chesapeake Bay Retriever” VSPACE=”4”
HSPACE=”12”>
3. Also, add the BORDER=”1” attribute:
<IMG SRC=”graphics/chessie.gif” ALIGN=”left”
ALT=”Chesapeake Bay Retriever” VSPACE=”4”
HSPACE=”12” BORDER=”1”>
Download other Visibooks for free at www.visibooks.com
42
4. Save the page and view it in the browser. It should now look like
this:
An HSPACE of 12 creates a A Border of 1 creates a 1-pixel
horizontal space of 12 pixels border around the graphic
around the graphic that nothing
can occupy
5. Move your cursor onto the graphic. The Alt textan alternative
text description of the graphicshould pop up.
The text should be aligned with the top of the graphic.
Tip: If you know the dimensions of a graphic, you can make it load
faster by specifying its width and height in pixels:
<IMG SRC=”graphics/chessie.gif” ALIGN=”left”
ALT=”Chesapeake Bay Retriever” VSPACE=”4”
HSPACE=”12” BORDER=”1” WIDTH=”150”
HEIGHT=”189”>
Download other Visibooks for free at www.visibooks.com
43
Practice: Insert graphics
A. Why should you specify Alt text for each graphic you insert?
1. Go to www.visibooks.com/dogpics. Save the German Shepherds
graphic in C:\dogs\graphics with the file name shepherds.gif.
2. Save the Yorkshire Terrier graphic in C:\dogs\graphics with the
file name yorkie.gif.
3. Insert shepherds.gif into the German Shepherds page in a new
paragraph below the heading.
4. Insert yorkie.gif into the Yorkshire Terriers page in a new
paragraph below the heading.
5. On the German Shepherds page, type German Shepherds are
smart dogs in a paragraph below the graphic.
6. On the Yorkshire Terriers page, type Yorkshire Terriers are
cute in a paragraph below the graphic.
7. On both pages, align the text to the side of the graphic, as on the
Chesapeake Bay Retrievers page.
8. On both pages, give the graphic a border of 1, vspace of 4, and
hspace of 12.
9. On all three Dog pages, put all paragraph text (not the main
headings) in the arial font, with a size of -1.
Answers
A. Alt tex t mak es it easier fo r visio n-impaired peo ple to understand a pages co ntent, and mak es it easier fo r search engines to
catalo g it.
Download other Visibooks for free at www.visibooks.com
44
Create a basic navigation system
Link back to the home page
1. In Notepad, open the Chesapeake Bay Retrievers page,
chesapeake.html.
2. Type the word Home in a new paragraph beneath the first
paragraph.
3. Enclose it in anchor tags that link it back to the home page:
<A HREF=”index.html”>Home</A>
Tip: Remember, index.html is the file name for the home page.
4. Save the page, and view it in the browser. The word Home should
now be a link, and the page should look like this:
5. On the German Shepherds page, create a link back to the home
page. Do this the same way you created the link for the Chesapeake
Bay retriever page.
6. On the Yorkshire Terriers page, create the same sort of link back to
the home page.
Download other Visibooks for free at www.visibooks.com
45
Link pages to each other
1. In Notepad, open the Chesapeake Bay Retrievers page.
2. Following the Home link, type:
| Chesapeake Bay Retrievers | German Shepherds |
Yorkshire Terriers
3. Make the words Chesapeake Bay Retrievers bold to
show site users You are here.
4. Link the words German Shepherds to the German Shepherds
page:
<A HREF=”german.html”>German Shepherds</A>
5. Link the words Yorkshire Terriers to the Yorkshire Terriers
page.
Download other Visibooks for free at www.visibooks.com
46
6. Save the page and view it in the browser. It should look like this:
Showing you are here
A sites navigational system should show people two things:
where they are, and where they can go.
To show people where they are, make the link corresponding
to the current page into plain text. This lets users know that if
they cant go to that page, they must be looking at it.
Home | Chesapeake Bay Retriev ers | German Shepherds | Yorkshire Terriers
You are here
Making the text bold reinforces the you are here message.
Download other Visibooks for free at www.visibooks.com
47
Use graphics as links
1. In Notepad, open the home page. Below the bulleted list of links, in
a new paragraph, insert the Chesapeake Bay Retriever, German
Shepherd and Yorkshire Terrier graphics:
<IMG SRC=”graphics/chessie.gif”>
<IMG SRC=”graphics/shepherds.gif”>
<IMG SRC=”graphics/yorkie.gif”>
2. Enclose the first image tag within anchor tags that link it to the
Chesapeake Bay Retriever page:
<A HREF=”chesapeake.html”><IMG
SRC=”graphics/chessie.gif”></A>
3. Save the page, then preview it in the browser. When you click on
the Chesapeake Bay Retriever graphic, it should take you to the
Chesapeake Bay Retriever page.
4. Go back to Notepad and add the BORDER=”0” attribute to the
first image tag:
<A HREF=”chesapeake.html”><IMG
SRC=”graphics/chessie.gif” BORDER=”0”></A>
Download other Visibooks for free at www.visibooks.com
48
5. Save the page and view it in the browser again. The blue link
border around the Chesapeake Bay Retriever graphic should be
gone:
Download other Visibooks for free at www.visibooks.com
49
Practice: Create a navigation system
A. Whats a good way to show site users You are here?
Task: To make your Dogs site look like the site at
www.visibooks.com/dogs.
1. In Notepad, open the German Shepherds page, german.html.
2. Following the Home link, type:
| Chesapeake Bay Retrievers | German Shepherds |
Yorkshire Terriers
3. Make the words German Shepherds bold.
4. Link the words Chesapeake Bay Retrievers and
Yorkshire Terriers to their corresponding pages.
5. Save the page.
6. Using the same system, create navigation links for the Yorkshire
Terriers page. Then save the page.
7. On the home page, link the German Shepherds graphic to the
German Shepherds page. Do the same for the Yorkshire Terriers
graphic.
8. Take out the link borders of these graphics.
9. When finished, preview your Dogs site in the browser. It should
look like the site at www.visibooks.com/dogs.
Answers
A. M ak e the link co rrespo nding to the current page bo ld, and plain tex t (no lo nger a link ).
Download other Visibooks for free at www.visibooks.com
50
Change page, link colors
Change background color of page
1. Open the home page in Notepad.
2. In the <BODY> tag, add the attribute BGCOLOR=”#ffffcc”:
<BODY BGCOLOR=”#ffffcc”>
3. Save the page and view it in the browser. The background color of
the page should now be pale yellow.
Hexadecimal colors
The ffffcc that stands for pale yellow is a hexadecimal
color. Hexadecimal colors allow you to specify colors more
precisely than you can with words. For example, you could use
the attribute BGCOLOR=yellow in the body tag and the page
background would turn bright yellow, but if you used
BGCOLOR=pale yellow, that wouldnt work.
For shades of color, hexadecimals must be used. They work
like this:
Computers show color as a mix of red, green and blue. In
hexadecimal colors, the first pair of letters or numbers signify
red, the second pair signify green, and the third pair signify
blue:
Red Green Blue
ff ff cc
Download other Visibooks for free at www.visibooks.com
51
Hexadecimal colors, continued
The color values go from the maximum amount of color (ff)
to no color at all (00):
Max Mid-range None
ff cc 99 66 33 00
Navy blue would be shown in hexadecimals as no red (00), no
green, (00), and a little bit of blue (66):
000066
A list of hexadecimal color codes is posted at:
www.webmonkey.com/reference/color_codes
Download other Visibooks for free at www.visibooks.com
52
Change link colors
1. In the home page, add the attribute LINK=”#ff0000” to the
<BODY> tag:
<BODY BGCOLOR=”#ffffcc” LINK=”#ff0000”>
This makes the links on the page show up in red.
2. Add the attribute VLINK=”#00ff00” to the <BODY> tag:
<BODY BGCOLOR=”#ffffcc” LINK=”#ff0000”
VLINK=”#00ff00”>
This makes visited links show up in green.
Tip: Visited links are links to pages that have already been viewed in
the browser.
Download other Visibooks for free at www.visibooks.com
53
3. Save the page and view it in the browser. The links on the page
should either be red or green.
Consistent link colors
Link colors should be consistent throughout a Web site. If the
links on one page are red, they should be red on every page.
Learning that red equals link once is much easier for people
than having to figure out the link color for each page or section
of a site.
Download other Visibooks for free at www.visibooks.com
54
Practice: HTML Basics
Task: To create a Web site about cats that looks like the site at
www.visibooks.com/cats.
1. Create a new home page and title it The Wonderful World of
Cats.
2. Save it in a new folder on the C:\ drive called Cats:
C:\Cats
3. Make the heading of the page read The Wonderful World of
Cats.
4. Below the main heading on the home page, insert a bulleted list:
House Cats
Alley Cats
Big Cats
5. Make these items arial, with a size of -1.
Download other Visibooks for free at www.visibooks.com
55
6. Link each list item to a new page about it. For instance, link
House Cats to a new page about house cats with file name
housecats.html.
7. On each of these new pages, put a descriptive heading at the top
of the page. For instance, the words “House Cats” at the top of
the house cats page.
8. Put the main headings of all four pages in the Arial font. Make
them bold. Give the home pages heading a size of +3. Give the
headings of the other pages a size of +2.
9. On each page, write a descriptive sentence or two in a new
paragraph below the main heading. Make it arial, with a size of -1.
10. Go to www.visibooks.com/catpics and get the three cat graphics
there. Put them in a folder called graphics within the C:\Cats
folder.
Download other Visibooks for free at www.visibooks.com
56
11. Insert the appropriate graphic on each of the 3 pages between the
main heading and the descriptive text below.
12. Align each graphic left, then specify vspace of 4 and hspace of 16.
13. Link each of the three cat pages back to the home page, and to
each other. On each page, make the you are here link into bold,
plain text.
14. Make the background color of each page light grey.
15. Make the link color on each page bright red. Make the visited link
color orange.
16. Preview the site in the browser. It should look like the site at
www.visibooks.com/cats.
Download other Visibooks for free at www.visibooks.com
57
Layout & Navigation
In this section, youll learn how to:
• Lay out pages using tables
• Create navigation bars
• Add subsections to site
• Place tables within tables
• Link to an external site using frames
Youll build a site that looks like this:
Download other Visibooks for free at www.visibooks.com
58
Lay out pages using tables
Tables and Web page layout
Almost all professional-quality Web sites are laid out using
tables. Just like a spreadsheet has cells that contain numbers, a
table on a Web page has cells that contain links, graphics, and
text.
The lines on this page clearly show its layout with table cells:
cell cell cell
Download other Visibooks for free at www.visibooks.com
59
Create a table
1. Create a new folder on the C:\ drive called Travel.
2. In Notepad, create a home page (file name index.html) titled
Traveling Down South. Save it in the Travel folder.
Tip: Make sure that your new home page has the correct file name
index.htmland all necessary tags:
<HTML>
<HEAD>
<!--Created by Your Name-->
</HEAD>
<TITLE>
Traveling Down South
</TITLE>
<BODY>
</BODY>
</HTML>
3. Youre going to create a simple one-row, two-cell table that looks
like this:
links content
4. The first step is to begin the table. Below the <BODY> tag, begin
your table with the <TABLE> tag:
<BODY>
<TABLE>
5. Below the <TABLE> tag, start a row with the <TR> (Table Row)
tag:
<BODY>
<TABLE>
<TR>
Download other Visibooks for free at www.visibooks.com
60
6. In the table row, start the first cell with the <TD> (Table Data) tag:
<BODY>
<TABLE>
<TR>
<TD>
7. After the <TD> tag, type the word links, then close the cell
with the </TD> tag:
<BODY>
<TABLE>
<TR>
<TD>Links</TD>
Youve created the first cell in the row:
links content
8. Now create the second cell in the row by adding a <TD> tag, the
word Content, and closing the cell with a </TD> tag:
<BODY>
<TABLE>
<TR>
<TD>Links</TD>
<TD>Content</TD>
links content
Download other Visibooks for free at www.visibooks.com
61
9. Finish the table by closing the row with a </TR> tag, then closing
the table with the </TABLE> tag:
<BODY>
<TABLE>
<TR>
<TD>Links</TD>
<TD>Content</TD>
</TR>
</TABLE>
Download other Visibooks for free at www.visibooks.com
62
10. You have set up the basic table. To make it possible to see the table
outlines in a browser, add the attribute BORDER=”1” to the
<TABLE> tag:
<BODY>
<TABLE BORDER=1>
<TR>
<TD>Links</TD>
<TD>Content</TD>
</TR>
</TABLE>
11. Save the page, then view it in the browser. It should look like this:
Download other Visibooks for free at www.visibooks.com
63
Format a table
1. Now youll extend the table. In Notepad, add the WIDTH=”100%”
attribute to the <TABLE> tag:
<BODY>
<TABLE BORDER=1 WIDTH=”100%”>
<TR>
<TD>Links</TD>
<TD>Content</TD>
</TR>
</TABLE>
2. Save the page and view it in the browser. It should look like this:
Download other Visibooks for free at www.visibooks.com
64
Percentage vs. fixed-width tables
When laying out a page using a table, set the tables width at
100%. That way, the contents of the page can stretch to fill the
whole monitor, regardless of the monitors resolution.
If you want it to fit a fixed-width table on all monitors, youre
limited to a table 580 pixels wide:
640 pixels
width of
- 20 pixels
browser offset: the
- 40 pixels
20 for the
= 580 pixels
width
low- distance that page vertical available
resolution content is indented scroll bar, for table
monitor from the sides of the plus 20 extra
browser
Creating pages with fixed-width tables offers precise control,
but wastes space on higher-resolution monitors:
Page:laid out using a table 580 pixels wide
Monitor used to view page:1280 pixels wide
Download other Visibooks for free at www.visibooks.com