Programming in HTML Completed in 1 DAY - AYOUB LRN
Programming in HTML Completed in 1 DAY - AYOUB LRN
HTML
Contents
1 IntroducingHTML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Introducing the Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 What Is an HTML Document? . . . . . . . . . . . . . . . . . . . 1
1.1.2 How Do You Create HTML Documents? . . . . . . . . . . . . 2
1.1.3 Some Typographic Conventions Used in This Book . . . . 4
1.1.4 Finding More Information About HTML . . . . . . . . . . . . 5
1.2 Your First HTML Document . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Accessing HTML Documents on the Web . . . . . . . . . . . . . . . . 7
1.4 Another Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Introducing HTML 1
…
</body>
</html>
The h tm l tag encloses all other tags and defines the boundaries of the
HTML document. We will return to the other tags later. The indenting used
to set off pairs of tags is optional, but it makes documents easier to create,
read, and edit. This style is part of good programming practice in all
languages.
Because HTML documents are just text documents, they can be created with
any text editor. Even Windows’ very basic Notepad application is a
workable choice for simple tasks.1 Once HTMLfiles have been created, you
can open them in your computer’s browser, hopefully without regard to
which browser you are using. As long as you give such documents an .htm
or . h t m lfile name extension, they should automatically open in your
browser when you double-click on thefile name. Although Windows
documents are no longer restricted to three-letter extensions, a convention
dating back to the preWindows days of MS-DOS operating systems, the
three-letter .htm extension is often used on Windows systems. The four-letter
. h t m l extension is commonly used on UNIX systems. However, either
extension is perfectly acceptable.
1 When you save afile in Notepad, the default extension is . t x t , so you will have to specify .htm
or . h t m l as afile extension.
There is one other consequence of using Windows computers for creating all
the code examples in this text: Windowsfile names are caseinsensitive, while
on UNIX systems, all spellings, includingfile names and commands, are
case-sensitive. In Windows, you can name a document newDocument.htm.
Later, you can spell it newdocument.htm, NEWDOCUMENT.HTM, or any
other combination of uppercase and lowercase letters and it won’t matter. On
a UNIX system, thatfile will be recognized only with the originalspelling.
Although you can create text (and, therefore, HTML) documents with a full-
featured word processor such as Microsoft Word, this is not recommended.
When you save a word processor document it no longer contains just the text
you have typed, but also all the layout and formatting information that goes
with that document. You can choose to save a document as just text with an
.htm extension, but it is easy to forget to do this.
RTF ( “rich text format”) documents are also unacceptable, as they still
retain some formatting information that is inappropriate for an HTML
document. Any document that contains“smart quotes” rather than "straight
quotes" can also cause problems, because smart quotes may not be displayed
properly by browsers. (This is much less of a problem on current browsers
than it used to be.)
There are commercial Web development tools that allow you to create Web
pages without actually knowing anything about HTML. These applications
are not suitable for use with this book. The obvious reason is that the
primary purpose of the book is to show you how to write your own HTML
documents to be used as an interface to a PHPfile. Also, these applications
may create HTMLfiles that are much larger and more complex than they
need to be. Such applications are better suited for Web development projects
that involve a lot of the other“bells and whistles” that make commercial Web
pages attractive.
Because of the small format of this book, line breaks in HTML document
examples, and later in PHP scripts, are often necessary and may sometimes
cause problems. Although every effort has been made to use line breaks in a
way that does not cause problems, it will sometimes be necessary to remove
breaks and“rejoin” some lines when you reproduce these documents for your
own use.
These exhaustive treatments will tell more than you will ever need to know
about using HTML!
1.2 Your First HTML Document
>1jvon@
Document 1.1 is certainly not very exciting. The point is that an HTML
document simply displays the static content you provide. As you will learn
in Chap. 2 , HTML provides many facilities for changing the appearance of
this content, but not the content itself.
HTML syntax is case-insensitive, which means that <html> is equivalent to
<HTML> or even <hTmL>. Some HTML document authors favor
uppercase spellings for tags because they stand out from the text content.
However, XHTML (extensible HTML), the apparent successor to HTML,
requires tags to be in lowercase letters.3 Hence, this text will always use
lowercase letters for tag names. Note that, despite previous warnings thatfile
names and commands are case-sensitive in some systems, browsers should
not be case-sensitive in their interpretation of HTML tags.
3 Although this book adopts some XHTML style rules, the documents are written in HTML and are
Documents intended for access by others on the World Wide Web are posted
on a Web server, a computer system connected to the Internet. Colleges and
universities typically provide Web servers for use by their faculty and
students. Individuals not affiliated with an institution may have to purchase
space on a commercial Web server, or they can set up their own server. In
any case, access to Web pages is universal in the sense that any computer
with an Internet connection and a browser can request to be connected to a
website through its Internet address—its Uniform Resource Locator (URL).
Not all HTML documents have to be publicly accessible on the Web. They
can be protected with logon identifications and passwords, or they can be
available only locally through an intranet (as opposed to the Internet). The
Internet is a global network of interconnected computers, whereas an
intranet is a local network that may or may not also provide connections to
the Internet. For example, a company can provide an intranet with no
external access, exclusively for internal use by its own employees.
Note that when you view HTML documents in the browser on your local
computer, they are not available on the Internet unless you have specifically
set up a server, assigned it a URL, and placed HTML documents in a folder
associated with that server. If you are associated with a university or other
institution, you may be able to put internet content on its server. Typically,
commercial providers of online services for individuals do not allow you to
set up servers with afixed URL. In that case, you have to purchase a domain
name and set up a URL with an Internet Service Provider (ISP) which
specializes in in Web hosting.
URLs usually start with the h t t p :// prefix, to indicate that the Hypertext
Transfer Protocol (HTTP) is being used. There are some variations, such as
h t t p s, indicating that the address that follows resides on a secure server, as
required forfinancial transactions, for example. The rest of the address
identifies a Web server and then a folder or directory on a computer system.
The .edu extension identifies this site as belonging to an educational
institution, in the same way as .gov, .com , and . o r g identify government,
commercial, and organization sites. Sometimes names in URLs are case-
sensitive, depending on the operating system installed on the computer
system containing the Web page. Users of Windows computers should note
the use of forward slashes rather than backslashes to separate folders (or
directories).
The i n dex .htm (or i n d ex . h tm l)file contains the home page for a web
site. By default, the i n dex .htm file is automatically opened, if it exists,
whenever this URL is accessed. That is, the address
As they were being developed, the HTML documents discussed in this book
resided neither on the Internet nor on an intranet. Instead, they were stored in
a folder on a local computer and accessed simply by doubleclicking on them.
You should create a separate folder on your computer as you work through
the examples in this book and write your own documents. You could make
documents you create yourself accessible on the Internet or an intranet by
placing them on a Web server. For example, if you are taking a course based
on this book, your instructor may require you to post homework assignments
on a Web site.
1.4 Another Example
This example shows how to include an image in an HTML document.
Document 1.2 (house.htm)
<html>
<head>
< t i t l e > O u r New H o u s e < / t i t l e > < s c r i p t
type="text/javascript">color='green'>This
document "+ d o c u m e n t . l a s t M o d ified + " < / f o n t > " ) ; < / s c r i
pt>
</head>
<body>
<h1>Our New House</h1>
<p>
language="javascript"
Although this book doesn’t deal with the JavaScript language, Document 1.2
does include one short but very useful JavaScript script:
<scriptlanguage="javascript"
type="text/javascript">document.write("<fontco
l o r = ' g r e e n ' > T h i s document was l a s t modified on "+ d o c u m e n
t . l a s t M o d ified + " < / f o n t > " ) ;
</script>
This script displays the date on which the document was last modi fied. It is
always a good idea to provide users of your documents (including yourself!)
with some information about how recent the document is. As you have
probably noticed, many websites do not include this information, so it is
impossible to tell whether information on that site is current or not.
There are several image formats that are widely used in HTML documents,
including image bitmaps (.bmp), Graphics Interchange Format (. g i f), and
Joint Photographic Experts Group(.j pg).
The original .jpgfile used in Document 1.2 has been compressed, and this
process can result in jagged edges where edges should be straight. This
effect is visible in the house framing and roof lines.
Within the img element, h e i g h t andwi dth attributes allow you to control
the size of the image display (in pixels). However, this is not necessarily a
good idea for photos like this because it is not equivalent to
actually“resizing” the image, as is possible with image-editing software.4
Hence, it is important to use images that initially are sized appropriately. The
house.jpg image was resized to 300 pixels high by 400 pixels wide, which
retained the height-to-width ratio of the original (cropped) photo. If a very
large highresolution imagefile is displayed as a very small image, using
thehei ght and wi dth attributes, the original largefile must still be
transmitted to the client computer. In view of the fact that high-resolution
images can produce very large files (>10 Mb), it is still important to consider
appropriate resolution and sizing for images included in HTML documents,
even in an age of high-speed broadband Internet connections and large
amounts of online storage space. (The size of the compressed
grayscalehouse.j pg image printed here is about 93 Kb.)
Document 1.2 could be made into a default home page simply by changing
its name toi ndex .htm.
Here is afinal admonition which hopefully does not sound too preachy:
Intellectual honesty and fairness in the use of other people’s material is
important, no matter what the setting. The image displayed by Document 1.2
was taken by this book’s author, of his own house under construction. In
other words, the author“owns” this image. Whenever you post images or
other material online, please be careful to respect intellectual property rights.
Your default approach should be that online materials are copyrighted and
cannot be used freely without permission. If you are in doubt about whether
you have permission to use an image or other material, don’t!
4 IrfanView
(www.irfanview.com) has been used for all image processing in this book.
Each of these four required elements has a start tag and an end tag. The < t i
t l e >…< / t i t l e > element is nested inside the <head>…</head> tag. This
element, which search engines use tofind documents on the Web, is required
even if you don’t include text for a title. Tags are always enclosed in angle
brackets <…>and the end tag always includes a forward slash before the
element name. The body element1 supports attributes that can be used to
control the overall appearance of an HTML document. Documents,
elements, attributes, and values are organized in a specific hierarchy: HTML
document ! elements ! attributes ! values
1 Often, this book will use just the name of the element, like body , to refer to the element with its
tags: <body>…</body> .
<body> … </body>
The body element contains the HTML document content, along with
whatever elements are required to format, access, and manipulate the
content.
Attributes : background , bgcolor ,text
<head> … </head>
The head element contains information about the document. The head
element must contain atitle element and under XHTML rules, thetitle
must be the first element afterhead .
Attributes : none
<html> … </html>
The html element surrounds the entire document. All other HTML
elements are nested within this element.
Attributes : none
<title> … </title>
The title element contains the text that will be displayed in the browser’s
title bar. Every HTML document should have a title, included as the first
element inside thehead element.
Attributes : none
The four basic elements discussed above constitute no more than a blank
template for an HTML document. Other elements are needed to display and
control the appearance of content within the document. Here are some
important elements that you will use over and over again in your HTML
documents. They are listed in alphabetical order. The list of attributes is not
necessarily complete, but includes only those which will be used in this
book. Because several elements can share common attributes, attributes and
their values are listed separately, following the list of elements.
<a> … </a>
<b> … </b>
Theb element forces the included text to be displayed in a bold font.
This is a“physical element” in the sense that it is associated specifically
with displaying text in a bold font.
Attributes : none
<br />
The br element inserts a break (line feed) in the text. Multiple breaks can be
used to insert multiple blank lines between sections of text. The break
element has no end tag because it encloses no content. Under XHTML rules,
a closing slash (after a space) must be included:<br /> . The slash is rarely
seen in older HTML documents, so its use will be encouraged but not
required.
Attributes : none
<center> … </center>
<font> … </font>
The font element controls the appearance of text. The two most commonly
used attributes control the size and color of the text. Attributes : size ,
color ,face
<hr />
The horizontal rule element draws a shaded horizontal line across the screen.
It does not have an end tag. A closing slash (after a space) is required in
XHTML. A noshade attribute displays the rule as a solid color, rather than
shaded.
Attributes : align , color , noshade , size ,width
<i> … </i>
i is a“physical element” that forces the included text to be displayed
in italics. The actual appearance may depend on the browser and computer
used.
Attributes : none
<img />
<p> … </p>
The p element marks the beginning and end of a paragraph of text content.
Note that HTML does not automatically indent paragraphs. Rather, it
separates paragraphs with an empty line, with all the text aligned left. It is
common to see only the start tag used in HTML documents, without the
corresponding end tag. However, the use of the end tag is enforced by
XHTML and this is the style that should be followed. Attributes : none
<pre> … </pre>
The default behavior of HTML is to collapse multiple spaces, line feeds, and
tabs to a single space. This destroys some of the text formatting that you
may wish to preserve in a document, such as tabs at the beginning of
paragraphs.
The pre element forces HTML to recognize multiple spaces, line feeds, and
tabs embedded in text. The default action forpre is to use a monospaced
font such asCourier . This may not always be appropriate. But, because
line feeds and other text placement conventions are recognized, pre is very
useful for embedding programming code examples within an HTML
document.
Attributes : none
Note that most of the elements described here require both start and end tags.
The general rule is that any element enclosing content requires both a start
and end tag. The <br /> and < hr /> elements, for example, do not enclose
content, so no end tag is needed.
Description of attributes:
These descriptions may not include all possible values. For a complete
listing, consult an HTML reference manual. Values of attributes should be
enclosed in single or double straight quotes, although HTML doesn’t enforce
this requirement.
align = "…"
Values : "left" , "right" , or"center"
Aligns text horizontally.
background = "…"
Value : the URL of a gif- or jpeg-format graphics file
border="…"
Value : The width, in pixels, of a border surrounding an image
color = "…"
Values : Text colors can be set either by name or by directly specifying the
intensity of red, green, and blue color components. See section 2.4 Selecting
and Using Colors.
face = "…"
Values : Font typefaces can be set either monospace , sans-serif , or
serif , or supported by theuser’s computer. The generic names should
always produce something that looks reasonable on any computer, but
specific font names that are not available on theuser’s computer may
produce unexpected results.
height = "…"
Value : The displayed height of an image in pixels (width="80" , for
example) or, when followed by a% sign (width="80%" , for example), as a
percent of total screen height. The displayed height overrides the actual
height of the image file—the number of rows in the image.
href = "…"
Value: The URL of an external or internal Web resource, or the name of an
internal document reference.
generically, with cursive ,
hspace = "…"
Value: The horizontal space, in pixels, between an image and the
surrounding text.
name = "…"
Value: The name assigned to an internal document reference through an “a ”
element.
size = "…"
Values : An unsigned integer from 1 to 7 or a signed number from +1 to +6
or -1 to -6.
src = "…"
Value : As an attribute for animg tag, the URL of a graphics file. For local
use, images and their HTML document are usually stored in the same folder.
text = "…"
Values : Thetext attribute, used with thebody element, selects the color of
text in a document, which prevails unless overridden by a font attribute.
vspace = "…"
Value: The vertical space, in pixels, between an image and the surrounding
text.
width = "…"
Values : The width of an image or horizontal rule, in pixels or as a percent of
total screen width, in percent. For example,width="80" is interpreted as a
width of 80 pixels, butwidth="80%" is a width equal to 80 percent of the
total screen width. The displayed width overrides the actual width of the
image file—the number of columns in the image.
Document 2.1 shows how to use some of these elements. Document 2.1
(tagExamples.htm)
The small checkbox graphic has been created with Windows ’ Paint
program. The actual text displayed in your browser is larger than this, but
the output image has been reduced in size (perhaps to the extent of not being
readable) tofit on the page. Also, because of the line feeds imposed on the
text of this code example by the page width, the output looks a little different
from what you might expect. So, you need to try this document on your own
browser.
Here are some style rules that will be used in this text. Under the
circumstances of HTML, they are more accurately referred to
as“guidelines.” Some of them will make more sense later on, as you create
more complicated documents.
Unlike some other languages, the HTML language is not sensitive to case.
Thus, <htm l >, <HTML>, and <hTmL> are equivalent. However, the
XHTML standard requires element names to be spelled with lowercase
letters. In the earlier days of HTML, many programmers adopted the style of
using uppercase letters for element names because they stood out in a
document. You will often still see this style in Web documents. Nonetheless,
this book will consistently use lowercase letters for element names.
2.Use the pre element to enforce text layout whenever it is reasonable to use
a monospaced font (such as Couri er).
Recall this markup in Document 2.1: Here i s some <b><i >pref ormatted t e
xt</i></b>
If you write thisas: Here is some
<b>
it is easy to see that the i element is properly nested inside the b element. If
this is changed to
<b><i>…{text} < / b > < / i >
with the order of the </b> and < / i > tags reversed, your browser probably
won’t complain, but it is not good programming style.
Good programmers always provide comments in their code for their own
benefit as well as for the benefit of others who might use their code. This
applies to HTML documents as well as to“real” programs. The syntax for
HTML comments, which can appear anywhere in a document, including
across multiple lines, is:
h t t p : / / www. m y u n i v e r si t y . e d u / * u se r n a m e
where the “~” symbol indicates a directory where web pages are stored.
Together with a user name, this URL directs a browser to the home Web
directory for that user. As noted in Chap. 1 , HTML documents are not
automatically Internet-accessible, and for the purposes of this book your web
pages may be accessible only locally on your own computer.
In this home directory there should be at least one file, called i n dex .htm (or
i n dex .htm l). UNIX systems favor the . h t m l extension, but Windows
users may prefer the three-character .htm extension because it is more
consistent with Windowsfile extension conventions. This is thefile that will
be opened automatically in response to entering the above URL. That is, the
i nd ex .htmfile is the“home page” for the Website. This home pagefile could
be named something different, but then its name would have to be added to
the URL:
An i nd ex .htmfile can contain both its own content as well as links to other
content (hyperlinks), including other pages on the user’s Website and to
external URLs. Here are four important kinds of links:
You can also make a“clickable image” to direct the user to anotherlink:
Syntax:<a href="{URL of web page} ">
<img src="{URL plus image name} " al i gn="…"
hei ght="…" width="…" / > < / a>
3. Links to email addresses.
An email link is an essential feature that allows users to communicate with
the author of a web page.
Syntax:<a href ="m ai l to:{ e mai l address} ">
{description of recipient} </a>
The careless speci fication of linked documents can make websites very
difficult to maintain and modify. As noted above, every website should have
a“home” directory containing an i ndex .htmfile. In order to make a site easy
to transport from one computer to another, all other content should be
contained either in the home directory or in folders created within that
directory. References to folders that are not related in this way should be
avoided, as they will typically need to be renamed if the site is moved to a
different computer. Although it is allowed as a matter of syntax to give a
complete (absolute) URL for a local web page, this should be avoided in
favor of a reference relative to the current folder.
This matter is important enough to warrant a complete example. Document
2.2a–c shows a simple website with a home folder on a Windows desktop
called home and two subfolders within the home folder named homework
and personal. Each subfolder contains a single HTML document,
homework.htm in homework and resume.htm in personal.
<html>
<head>
< t i t l e >My P a g e < / t i t l e >
</head>
<body>
<! –– These absolute lin k s are a bad id e a! – –>
Here are l i n k s to
< a h r e f = " C : / D o c u m e n t s and S e t t i n g s / D a v i d / d e s k t o p
/ /Book/hom ework.htm "> hom ework</a> and
< a h r e f = " C : / D o c u m e n t s and
Settings/
David/desktop/Book/resume.ht
m">
p e r so n a l docum ents.</a>
</body>
</html>
<html>
<head>
<title>Resume</title>
</head>
<body>
Here i s myrésum é. < / b o d y >
</html>
Note that Document 2.2a uses forward slashes to separate the directories
andfile names. This is consistent with UNIX syntax, but Windows/DOS
systems use backward slashes. Forward slashes are the HTML standard, and
they should always be used even though backward slashes may also work.
Another point of interest is that UNIX directory paths andfilenames are case-
sensitive, but Windows paths andfilenames are not. This could cause
problems if you develop a web page on a Windows computer and then move
it to a UNIX-based system. As a matter of style, you should be consistent
about case in directory andfile names even when it appears not to matter.
Note how the“é”s in résumé, which are not keyboard characters, are
produced by using the escape sequence é—see Appendix 2.
<html>
<head>
< t i t l e >My P a g e < / t i t l e >
</head>
<body>
<! –– Use these r e l a t i v e lin k s instead! ––>
Here are l i n k s to
<a
h r e f = " h o m e wo r k / h o m e wo r k . h t m " >
homework</a> and
<a h r e f = " p e r s o n a l / r e s u m e . h t m " >
p e r so n a l docum ents.</a>
</body>
</html>
Paying proper attention to using relative URLs from the very beginning
when designing a website will save a lot of time in the future!
2.4 Selecting and Using Colors 25
2.4 Selecting and Using Colors
As previously noted, several attributes, such as bgcol or, are used to set
colors of text or backgrounds. Colors may be identified by name or by a
sixcharacter hexadecimal numeric code that, historically, specified the
strength of the signal emitted from the red, green, and blue electron“guns”
that excited the corresponding phosphors on a cathode ray tube color screen.
This convention has been retained even though other monitor
display technologies are used now. The hex code2 is in the format #RRGGBB
where each color value can range from 00 (turned off) to FF (maximum
intensity).
There are many color names in use on the Web, but only 16 are completely
standardized, representing the 16 colors recognized by the Windows VGA
color palette. These colors are listed in Table 2.1 . The problem with
additional color names is that there is no enforced standard for how browsers
should interpret them. Two examples: magenta probably should be, but
doesn’t have to be, the same as fuchsia; ivory is a nonstandard color that
should be rendered as a yellowish off-white. The colors in Table 2.1 are
standardized in the sense that all browsers should associate these 16 names
with the same hexadecimal code. Of course, variations can still occur
because monitors themselves will respond somewhat differently to the same
name or hex code; blue on my computer monitor may look somewhat
different than blue on your monitor.
Note that the standardized colors use a limited range of hex codes. With the
exception of silver (nothing more than a lighter gray), the RGB gun colors
are either off (00), on (FF), or halfway on (80).
What should you do about choosing colors? Favor standardized colors, and
if you wish to make an exception, try it in as many browser environments as
possible. Be careful to choose background and text colors so that text will
always be visible against its background. The safest approach for
#FFFF00
2 Hex code = hexadecimal code, a base-16 numbering system using integers 0–9 and letters A–F to
represent values ten tofifteen.
setting colors in the body element is to specify both background and text
colors. This will ensure that default colors set in a user’s browser will not
result in unreadable text.
If you ’re not sure whether a color name is supported and what it looks like
on your monitor, you have nothing to lose by trying it. If you set b g c o l o r
= " l i g h t b l u e ", you will either like the result or not. If a color name
isn’t recognized by your browser, the result will be unpredictable, but not
catastrophic. There are (of course!) numerous websites that will help you
work with colors, including getting the desired result with hex codes.
As you create more web pages, you may wish to impose a consistent look
for all your pages, or for groups of related pages. It is tedious to insert
elements for all the characteristics you may wish to replicate—font size, font
color, background color, etc. Style sheets make it much easier to replicate
layout information in multiple sheets. A complete discussion of style sheets
is far beyond the scope of this book, as there are many different kinds of
style sheets, many ways to make use of them, and many browser-specific
nuances. This book will use cascading style sheets (CSS), which are widely
accepted as a default kind of style sheet, but will present only a small subset
of all the possibilities! By way of introduction, Document 2.3 shows how to
use a s t y l e element to establish the default appearance of the body of an
HTML document.
</body>
</html>
The s t y l e element has an optional t i t l e attribute and a t y pe attribute set
equal to " t e x t / c s s ", where the css stands for cascading style sheet.
Inside the s t y l e element, dot notation is used to assign a class name, b r i g
h t, to the body element: body . b r i g h t. Inside curly brackets attributes are
assigned values, with each attribute and its value being separated by a
semicolon. Then, the <body> tag assigns the class name b r i g h t as the
value of the c l a s s attribute. As a result, the document background color is
red, with the font set to a blue, bold, italicized 16-point serif font.
Any HTML tag that encloses content can be assigned a class value defined
in a style element. For this simple example, with styles applying only to a
single body element, the class name is optional. With no class name and no c
l a s s attribute in <body>, the style rules will automatically be applied to the
entire HTML document.
In general, several different style rules can apply to the same HTML
element. For example, several style rules could be established for paragraphs
(<p>…</p>), each of which would have its own class name.
How did CSS get that name? Because the properties set for an element
cascade down, or are“inherited,” by other elements contained within that
element unless those elements are assigned their own style properties. So,
for example, properties set for the body element are inherited by the p and
h1 elements, because these are contained within the body element. Properties
set for the head element are inherited by content appearing in the t i t l e
element.
CSS can be used to modify the appearance of any HTML element that
encloses content. Here are some properties that can be specified in style
sheets.
Background properties
background-col or
When used in a body element, backgroun d-c ol or sets the background color
for an entire document. It can also be used to highlight a paragraph, for
example, when used with a p element.
background-image
This property is used with a URL to select an image file (gif or jpeg) that
will appear as a background. Typically, this is used with a body element, but
it can also be used with other elements, such as p. For other background
properties that can be used to control the appearance of a background image,
consult an HTML reference text.
background
This allows you to set all background properties in a single rule.
Color property
The c o l o r property sets the default color for text, using the descrip
tions discussed in Sect. 2.4 .
Font properties
font-family
Example: f o n t - f a m i l y : A r i a l , s a n s - s e r i f ;
font-size
This property allows you to set the actual or relative size of text. You can use
relative values, such as l a r g e , s m a l l , l a r g e r , sm a l l e r (relative to
a default size); a percentage, such as 200%of the default size; or an actual
point size such as16pt. Some sources advise against using absolute point
sizes because a point size that is perfectly readable on one system might be
uncomfortably small on another. But, for our purposes, specifying the point
size is a reasonable choice.
Example: f o n t - s i z e : 2 4 p t ;
font-style
This property allows you to specify n o r m a l , i t a l i c , or o b l i q u e
fonts. Example: f o n t - s t y l e : i t a l i c ;
font-weight
This propertyallows you to select the font weight. You can use values in the
range from 100 (extra light) to 900 (extra bold), or words: e x t r a - l i g h t ,
l i g h t , d e m i - l i g h t , medium, d em i - b o l d, bol d, and e x t r a - b o l
d. Some choices may not have a noticeable effect on some fonts in some
browsers.
Example: f o n t - w e i g h t : 900;
font
This property allows you to set all font properties with one style rule.
Table 2.2 Some font families Generic Name
Example
Script MT Bold
Courier
Arial
Example: f o n t : i t a l i c 18pt H e l v e t i c a , s a n s - s e r i f ;
How will your browser interpret a font name? For the generic name s e r i f,
it will pick the primary serif font it supports—probably Times or Times
Roman. Browsers will probably also recognize specific font names such as
Times or Helvetica (a sans-seriffont). If you specify a font name not
supported by your browser, it will simply ignore your choice and use its
default font for text. It is possible to list several fonts, in which case your
browser will select thefirst one it supports. For example, consider this style
specification:
font-family:Arial,Helvetica,sans-serif;
Your browser will use an Arial font if it supports that, Helvetica if it doesn ’t
support Arial but does support Helvetica, or,finally, whatever sans-serif font
it does support by default. By giving your browser choices, with the generic
serif or non-serif name as the last choice, you can be reasonably sure that
text will be displayed approximately as you wish it to appear.
Text properties
Of the many text properties, here are just three that may be useful.
t e x t -align
This is used in block elements such as p. It is similar in effect to the
HTML a l i g n attribute. The choices are l e f t , r i g h t , center, and
j u s t i f y. With large font sizes, j u s t i f y may produce odd-looking
results.
Example: t e x t - a l i g n : c e n t e r ;
t e x t -indent
Recall that paragraphs created with the p element do not indent the first
word in the paragraph. (HTML inserts a blank line and left-justifies the text.)
This property allows you to set indentation using typesetting notation or
actual measurements. An actual English or metric measurement—inches
inches (in), millimeters (mm), or centimeters (cm)—may be easiest and will
always give predictable results.
Example: t e x t - i n d e n t : 0 . 5 i n ;
whi te-space
The value of this property is that you can prevent spaces from being ignored.
(Remember that the default HTML behavior is to collapse multiple spaces
and other non-printable characters into a single blank space.) Some older
browsers may not support this property. You can use the HTML pre element
by itself, instead, but this causes text to be displayed in a monospaced font
such as Courier. The example given here retains white space regardless of
the typeface being used.
Example: wh i t e - sp a c e : p r e ;
Styles aren ’t restricted just to the body element. For example, paragraphs
(<p>…</p>) and headings (<hn >…</hn >) can also have styles associated
with them. You can also set styles in selected portions of text, using the span
element, and in blocks of text using the d i v element.
<div> … </div>
Attributes:align ,style
<span> … </span>
Attributes : align ,style
Values for align : "left" (default),"right" , "center"
You can create style sheets as separate files and then use them whenever you
wish to use a particular style on a web page. This makes it easy to impose a
uniform appearance on multiple web pages. Document 2.4a and 2.4b show a
simple example.
body { b a c k g r o u n d : s i l v e r ; c o l o r : w h i t e ; f o n t : 2 4 p t
Times} h1 { c o l o r : r e d ; f o n t : 1 8 p t I m p a c t ; }
h2 { c o l o r : b l u e ; f o n t : 1 6 p t C o u r i e r ; }
<html>
<head>
< t i t l e > S t y l e Sheet E x a m p l e < / t i t l e > < l i n k h r e f = " b o d y
.css"
Here i s some t e x t .
</body>
</html>
This example shows how to create a file, body.css, containing style elements
that can be applied to any document by using the l i n k element, as in
Document 2.4b. The . c s s extension is standard, but not required. (You
could use . t x t, for example, although there is no reason to confuse matters
by doing that.) This example is very simple, but the concept is powerful
because it makes it easy to create a standard style for all your documents
which can be invoked with the l i n k element. The Impact font chosen for h1
headings may not be supported by all browsers. If not, a default font will be
used in its place.
The attributes of l i n k include href, which contains the URL of the style
sheet file, the r e l = " s t y l e s h e e t " (relationship) attribute, which
describes how to use thefile (as a style sheet), and the type, which should be
" t e x t / c s s ", just as it would be defined if you created a s t y l e element
directly in the head element. In this example, body.css is in the same folder
as st yl e 2. h tm. If you keep your style sheets in a separate folder, you will
of course need to reference that folder.
This discussion has barely scratched the surface of style sheets. Style sheets
can make your web pages more visually appealing and can greatly simplify
your work on large Web projects. Some developers advocate replacing all
individual formatting elements, such as f o n t and its attributes, with style
sheet specifications. Despite the fact that the use of individual formatting
elements is“deprecated” in favor of using CSS, there is little likelihood that
support for individual elements will disappear from browsers in the
foreseeable future. For the kinds of applications discussed in this book,
cascading style sheets may sometimes be convenient, but they are not
required.
p . r e d { b a c k g r o u n d : r e d ; c o l o r : b l u e ; f o n t : 2 0 p t Times}
div.white{background:white;color:red;font:20pt
Times} s p a n . b l u e
{ b a c k g r o u n d : b l u e ; c o l o r : w h i t e ; f o n t : 2 0pt Times}
<html>
<head>
< t i t l e >A Red, W h i t e, and Bl ue D o c u m e n t < / t i t l e >
<linkhref="rwb.css"rel="stylesheet"type="text/
c s s " />
</head>
<body>
<i m g s r c = " s t a r s . j p g " h e i g h t = " 1 5 0 " wi d t h = " 2 5 0 " /> <p
class="red">
T h i s t e x t shoul d be b l u e on a red background.
</p><p><divclass="white"style="font-style:ital
i c ; " > T h i s t e x t shoul d be red on a wh i t e background. < / d i v > < / p
>
< p > < sp a n c l a s s = " b l u e " > T h i s t e x t shoul d be wh i t e on a b l
u e b a c k g r o u n d . </sp a n >
</p>
</body>
</html>
The stars, which are supposed to be red, silver, and blue, have been drawn
using Windows’ Paint program.
This chapter shows how to use HTML tables, forms, lists, and frames to
organize documents and provide a framework for interfacing with PHP
applications.
HTML table and form elements are the two most important ways to organize
the content of a web page. Forms are critical because they provide the
interface with PHP. Sometimes it is helpful to organize information in a form
through the use of one or more tables. With that approach in mind,first
consider tables.
Because HTML ignores text formatting, such as white space and line feeds
(the Enter key), it can be difficult to control the placement of content on a
web page. The addition of images only compounds this problem. An easy
way to gain some control is to create a table, using the table element. Then
the relative locations of text and graphics can be established by entering
them into cells of the table. Within the start and end tags, <ta bl e >…< / tabl
e>, rows and cells are defined with thetr (“table row”) and td (“table data”)
elements. These elements are nested as follows:
<table>
<tr>
<td>… </td> {as many columns as you need …} …
</tr>
{as many rows as you need …}
…
</table>
The < t r >…< / t r > tags define the rows and the <td>…</td> tags define
cells in columns within those rows. You can define as many rows and
columns as you need to organize information in a familiar spreadsheet-like
row-and-column format. Document 3.1 shows how to use a table to organize
and display some results from residential radon testing.
<html>
<head>
< t i t l e> Radon T a b l e< / t i t l e >
< / h ea d >
<body>
<h1> Resul ts o f radon t e s t i n g< / h 1 >
<p>
The t a b l e below shows some radon l e v e l s measured i n r e si d e n c e
s.< b r / > For v a l u es g r e a t e r than o r equal t o 4 p C i / L , a c t i o n
shoul d be t a k e n< b r / > t o reduce t h e c o n c e n t r a t i o n o f radon g a
s. For v al ues g r e a t e r than or< b r / > equal to 3 p C i / L , r e t e s t i n g is
recommended.
</p>
<table>
In a color rendition of this page, thefirst value will have a pink background,
the second a yellow background, and the others a light green background.
The syntax for tables includes several possibilities in addition to tr and td for
customizing appearance. These include the c a p t i o n element, which
associates a caption with the table, and the th element, which is used to
create a“header” row in a table by automatically displaying text in bold font.
(Theth element can be used anywhere in a table in place of td.) The c a pti o
n, td, th, andtr elements are used only inside the start and end tags of a t a b l
e element: <tabl e>…</table>. With these elements, a more comprehensive
table layout looks like this:
<table>
<capti on>…< / c a p t i o n >
<tr>
<!–– Use o f t h i n p l a c e o f t d i s o p t i o n a l . ––>
…
</tr>
…
</table>
<caption> … </caption>
Displays the specified text as a caption for a table. Earlier versions of HTML
support only"top" (the default value) or"bottom" for the value of
thealign attribute. Some browsers may allow"center" as a value
foralign , which might often be the alignment of choice for a table caption.
Attributes :align
<table> … </table>
Contains table-related and other elements.
Attributes : border , bordercolor , cellpadding , cellspacing ,
width
<tbody> … </tbody>
Groups rows within the body of a table so each group can be given different
attributes and styles.
Attributes:align , char , charoff ,valign
<td> … </td>
Defines data cells in the rows of a table. Does not contain other tablerelated
elements.
Attributes : align , bgcolor , char , charoff , colspan , nowrap ,
rowspan ,width
<th> … </th>
<tr> … </tr>
Defines rows in a table. Contains td orth elements.
Attributes : align , bgcolor ,valign
Description of attributes:
align = "…"
Values : "left" , "right" , or"center"
Aligns text horizontally. When align is specified in atr element, its value
will be overridden if it is specified again within atd element in that row.
bgcolor = "…"
Values : color names or hexadecimal values "# RRGGBB "
Sets the background color for a cell or row. When bgcolor is specified in
atr element, its value will be overridden if it is specified again within a td
element in that row.
border = "…"
Values : an integer number of pixels
Adds a border to the table and its cells. A value is optional. If it is included,
a colored (or gray, by default) border is added around the outer boundary of
the table.
bordercolor = "…"
Values : color names or hexadecimal values"# RRGGBB "
Sets the color of a table border.
cellpadding = "…"
Values : an integer number of pixels
Defines vertical spacing between cells in a table.
cellspacing = "…"
Values : an integer number of pixels
Defines horizontal spacing between cells in a table.
colspan = "…"
Values : an integer
Defines how many columns a cell will span.
nowrap
Prevents text from being automatically wrapped within a cell. It does not
have a value.
rowspan = "…"
Values : an integer
Defines how many rows a cell will span.
valign = "…"
Values : "top" , "middle" , or"bottom"
Aligns text vertically. When valign is specified in atr element, its value
will be overridden if it is specified again within atd element in that row.
width = "…"
Values : a number or a percentage
Specifies table or cell width in pixels (width="140" ) or as a percentage
of the window or table header width (width="80%" ).
The attributes associated with these tags all have default values or are just
ignored if you don’t use them. You can create a table without using any
attributes and then add attributes as needed. When creating tables, it is often
useful to include the b or de r attribute, which can be removed when you are
happy with how the table looks. In Document 3.1, the only specified
attribute is the background color in some cells. An easy way to familiarize
yourself with the effects of specifying table attributes and their values is to
experiment with Document 3.1.
Document 3.1 is not very useful except for showing how to create tables.
The radon values and the colors associated with them are all“hard coded”
values. There is no provision for changing the radon values, and even if you
could do that, you couldn’t use HTML to change the background colors in
response to the radon values. However, if the radon values and perhaps the
site names are entered into i n p u t elements, PHP can be used to generate a
table with background colors calculated based on the radon values entered.
(See Document 4.1.)
The tbody element allows a table to be divided into two or more groups of
rows. Each group of rows enclosed by a <tbody>…</tbody> tag can have its
own attributes and can have different pre-defined c l a s s attribute values.
Document 3.2 shows a simple example in which rows in a table are grouped
by background color.
<html>
<head>
< t i t l e > U s i n g t h e tbody e l e m e n t < / t i t l e >
<style>
th{background-color:black;
color:white;}tbody.cold{text
align:center;
font-weight:bold;background-color:gray;}tbody.
cool{text-align:center;
font-weight:bold;background
color:silver;}tbody.hot{text
align:center;
f o n t - w e i g h t :bold; b a c k g r o u n d - c o l o r : i v o r y ; } < / s t y l e
>
</head>
<body>
< t a b l e border>
< t r > < t h > M o n th </ th > <t h > Av e r a g e < b r />Temperature < b r
/>& d e g ; F < / t d > < / t r >
<tbodyclass="cold">
<tr><td
>January</td><td>30.4</td></tr>
<tr><td>February</td><td>33.0</td></tr
>
<tr><td>March</td><td>42.4</td></tr>
</tbody>
<tbodyclass="cool">
<tr><td>April</td><td>52.4</td></tr>
<tr><td>May</td><td>62.9</td></tr>
</tbody>
<tbodyclass="hot">
<tr><td>June</td><td>71.8</td></tr>
<tr><td>July</td><td>76.7</td></tr>
<tr><td>August</td><td>75.5</td></tr>
</tbody>
<tbodyclass="cool">
<tr><td>September</td><td>68.2</td></t
r>
<tr><td>October</td><td>56.4</td></tr>
</tbody>
<tbodyclass="cold">
<tr><td>November</td><td>46.4</td></tr
>
<tr><td>December</td><td>35.8</td></tr
>
</body>
</html>
If you are familiar with creating tables in a word processing application, you
know that it is easy to create more complicated table layouts by merging
cells across rows and columns. You can also do this with HTML tables,
using the col span and rowspan attributes. Document 3.3 shows a table that
displays cloud names, altitudes, and whether they produce precipitation or
not.
<html>
<head>
<title> C l o u d Type C h a r t< / t i t l e >
< / h ea d >
<body>
<table border="2">
< c a p t i o n > C l o u d Type C h a r t< / c a p t i o n >
<tr>
<th a l i g n =" c e n t e r " > A l t i t u d e< / t h >
< t h col span="2"> Cl oud Nam e</ t h></ t r >
<tr><td a l i g n =" c e n t e r " rowspan="3"> Hi gh</ t d> < t d c o l s p a n =" 2 " >
C i r r u s< / t d > < / t r >
< t r > < t d c o l sp a n =" 2 " > C i r r o c u m u l u s< / t d> < / t r > < t r > < t d c o l s
p a n =" 2 " > C i r r o s t r a t u s< / t d > < / t r > < / t r >
<tr><td a l i g n =" c e n t e r " rowspan="2"> Mi ddl e</ t d> < t d c o l sp a n =" 2 "
> A l t o c u m u l us< / t d > < / t r > < t r > < t d c o l s p a n =" 2 " > A l t o s t r a t u
s< / t d > < / t r > < / t r >
<tr><td a l i g n =" c e n t e r " rowspan="5"> Low</td> <t d> Cum ul us</ td>
< t d > n o n p r e c i p i t a t i n g< / t d > < / t r >
Altitude
High
Middle
Low
Cloud Type Chart Cloud Name Cirrus
Cirrocumulus
Cirrostratus
Altocumulus
Altostratus
Cumulus
Altocumulus
Stratocumulus
Cumulonimbus
Nimbostratus
nonprecipitating nonprecipitating nonprecipitating
precipitating precipitating
3.2 The f orm and i n p u t Elements
HTML forms are defined by the f orm element, using start and end tags:
<form>…</f orm > tags. The attributes of the f orm element are:
action = "…"
Value : a programmer-supplied URL that identifies a processing script, PHP
file name, ormailto: followed by an email address. For example,
action="mailto:my_mail@my_univ.edu" .
enctype="…"
Value : enctype="text/plain" is the usual value, but it is not needed
whenmethod="post" is used with PHP applications.
method = "…"
Values : "get" ,"post"
Controls how data from a form is sent to the URL, PHP file, or email
address identified in theaction attribute. In this book, the"post" value is
used because it is the easiest way to transmit form data in an easily usable
format.
name = "…"
Value : a programmer-selected name that is used to identify the form.
Thename attribute is needed only if a document contains more than one
form.
Forms contain one or more input fields identified by < i n p ut /> tags.
Because the i n p u t element does not enclose content, it has no end tag, so it
requires a closing slash for XHTML compliance. The most important
attribute of i n p u t is its type. There are severalfield types that have
welldefined default behaviors in HTML. The possible values are listed in
Table 3.1 .
Table 3.1 Values for thei n p u t element’s t ype attribute
Field type
t ype = " b u t t o n "
Description
Provides a programmer-defined action to be associated with the field through the use of an event
handler such as on c l i c k t ype = "c hec k box" Allows selection of one or more values from a set of
possible
values
t ype = "hidd e n " Allows the definition of textfields that can be accessed by a PHP
script but are not displayed in a document
t ype = "passw or d"
t ype = " r a d i o "
Allows entry of character data but displays only asterisks Allows selection of one and only one value
from a set of possible
values
t ype = " r e s e t "
t ype = " s u b m i t "
t ype = " t e x t "
Used to reset all formfields to their default values Processes form contents according to method and ac
t i on Allows entry of character data
There is no field type specifically for numerical values. In some
circumstances, this can be an issue, but as will be seen later, it presents no
problem for sending values from an i n p u t element to a PHP application.
maxlength="…"
Value : Maximum number of characters that can be entered in the field. This
value can be greater than the value given for thesize attribute.
name="…"
Value : A programmer-supplied name for the field. The name should follow
the variable-naming conventions for PHP in order to facilitate its use in PHP
scripts.
readonly
Value : none
Prevents field values intype="text" ortext="password" from being
changed.
size="…"
Value : width of the displayed field, in characters.
type="…"
Values : See Table 3.1.
value="…"
Value : a programmer-supplied default value that will be displayed in the
field. This value can be overridden by user input unless thereadonly
attribute is also specified.
The form element typically contains a combination of text and input fields.
The text can be used to explain to the user of the form what kind of input is
expected. Document 3.4 gives a simple example that uses several inputfield
types:
<html>
<head>
< t i t l e > D a t a R e p o r ti n g S i t e I n f o r m a t i o n < / t i t l e > < / h
ead>
<body>
< f o rm >
or S
Please enter your longitude: 75 E
or W
Please enter your elevation: meters
Please indicate the seasons during which your site reports data: Winter:
Spring: Summer: Fall:
Note that some of the text fields are blank because no default v al ue
attribute has been specified. These require user input, and there is no way to
establish ahead of time what this input might be. However, it may still be
worthwhile in some cases to provide a default value if that would help the
user to understand what is required. When the allowed input choices can be
limited ahead of time by the creator of the document, it is appropriate to use
The same basic rules apply to checkboxfields. You can have more than one
group of checkboxes, each with its unique name. The only difference is that
you can select as many boxes as you like within each group, rather than just
one value with r a d i o fields.
A common feature on web pages that use forms is a pull-down list. The s e l
e c t and o p t i o n tags provide another way to limit the input choices a user
can make on a form. The implementation described here is similar to a group
of radio buttons in the sense that only one item can be selected from a list.
This can simplify a document interface and eliminate the need for some
input checking that might otherwise need to be done if a user is free to type
whatever she/he likes in an inputfield. For example, creating a pull-down list
of the months of the year eliminates the need for a user to type (and perhaps
to mistype) the name of a month, as shown in Document 3.5.
<html>
<head>
<title>Pull-DownList</title>
</head>
<body><f orm >
S e l e c t a month f rom t h i s menu:
</select>
</form></body>
</html>
Including si z e = "12 " ensures that all the months will be visible. Without
this attribute, HTML can add a scroll bar to the list.
For the output shown, the user has chosen the month of April, which is now
highlighted. The values of thev al ue attribute can be, but do not have to be,
the same as the text displayed for each option. In this case, the month values
are numbers between 1 and 12, rather than the names of the months.
Assigning the se l e c t e d attribute to the first option means that “January”
will be highlighted when the pull-down box isfirst displayed. For longer
lists, the default action is for HTML to include a scroll bar alongside the list.
Adding the m u l t i p l e attribute to the < se l ect> tag allows more than one
selection to be made by holding down the Control key on Windows
computers or the Command key on Mac Computers.
Although it is easy to create pull-down lists as well as groups of radio
buttons and checkboxes, it is not yet obvious how to make use of the
selections a user makes. As will be shown in subsequent chapters, PHP
provides the required capabilities.
3.4 Combining
Tables and Forms
<html>
<head>
<title>ObservationSiteDescriptions</title></hea
d>
<body>
< f o rm >
<tableborder="2"cellpadding="5"
cellspacing="2"align="center">
< c a p t i o n > < f o n t si z e = " +2"> Ob se rv ati o n S i t e D e s c r i t i o
ns</font></caption>
<trbgcolor="lightblue">
<th>Site#</th><th>Site
N a m e < / t h > < t h > L a t i t u d e < / th >
<th>Longitude</td><th>Elevation</th></tr>
<trbgcolor="palegreen">
<td>Site1</td>
< t d > < i n p u t t y p e = " t e x t " name="Name1"
s i z e = " 1 0 " m ax length="10" v al ue= "Name1" / > < / t d >
<td><inputtype="text"name="Latitude1"
size="10"
m ax l ength="10"
value="Latitude1"
/></td>
< t d > < i n p u t t y p e = " t e x t " n a m e = "L on gi tu de 1" s i z e = " 1 0
" m ax length= "10" v a l u e = " L o n g i t u d e 1 " / > < / t d >
<td><inputtype="text"name="Elevation1"
size="10"
m ax l ength="10" v a l u e = " E l e v a t i o n 1 " / > < / t d > < / t r >
<trbgcolor="ivory">
<td>Site2</td>
< t d > < i n p u t t y p e = " t e x t " name="Name2"
s i z e = " 1 0 " m ax length="10" v al ue= "Name2" / > < / t d >
<td><inputtype="text"name="Latitude2"
size="10"
m ax l ength="10" v a l u e = " L a t i t u d e 2 " / > < / t d >
< t d > < i n p u t t y p e = " t e x t " n a m e = "L on gi tu de 2" s i z e = " 1 0
" m ax length= "10" v a l u e = " L o n g i t u d e 2 " / > < / t d >
<td><inputtype="text"name="Elevation2"
size="10"
m ax l ength="10" v a l u e = " E l e v a t i o n 2 " / > < / t d > < / t r >
<trbgcolor="palegreen">
<td>Site3</td>
m ax l ength="10" v a l u e = " L a t i t u d e 3 " / > < / t d > < t d > < i n p u t
t y p e = " t e x t " n a m e ="L on gi tu de 3" s i z e = " 1 0 " m ax length=
"10" v a l u e = " L o n g i t u d e 3 " / > < / t d >
<td><inputtype="text"name="Elevation3"size="
1 0 " m ax l ength="10" v a l u e = " E l e v a t i o n 3 " / > < / t d > < / t r >
<trbgcolor="ivory">
<td>Site4</td>
< t d > < i n p u t t y p e = " t e x t " name="Name4"
s i z e = " 1 0 " m ax length="10" v al ue= "Name4" / > < / t d >
<td><inputtype="text"name="Latitude4"size="1
0 " m ax l ength="10" v a l u e = " L a t i t u d e 4 " / > < / t d > < t d > < i n
p u t t y p e = " t e x t " n a m e ="L on gi tu de 4" s i z e = " 1 0 " m ax
length= "10" v a l u e = " L o n g i t u d e 4 " / > < / t d >
<td><inputtype="text"name="Elevation4"size="
1 0 " m ax l ength="10" v a l u e = " E l e v a t i o n 4 " / > < / t d >
</tr>
<trbgcolor="palegreen">
<td>Site5</td>
< t d > < i n p u t t y p e = " t e x t " name="Name5"
s i z e = " 1 0 " m ax length="10" v al ue= "Name5" / > < / t d >
< t d > < i n p u t t y p e = " t e x t " n a m e = " L a t i t u d e 5 " si z e = " 1 0
" m ax l ength="10" v a l u e = " L a t i t u d e 5 " / > < / t d > < t d > < i n p
u t t y p e = " t e x t " n a m e ="L on gi tu de 5" s i z e = " 1 0 " m ax length=
"10" v a l u e = " L o n g i t u d e 5 " / > < / t d >
<td><inputtype="text"name="Elevation5"size="
1 0 " m ax l ength="10" v a l u e = " E l e v a t i o n 5 " / > < / t d >
</tr>
</table
>
< / f o r m > Site # Site Name Latitude </body>
< / h t m l > Site 1 Name1 Latitude1
Longitude Elevation
Longitude1 Elevation1
Site 2 Name2 Latitude2 Longitude2 Elevation2
Site 3
Name3
Observation Site Descritions
Latitude3 Longitude3
Elevation3
Longitude4 Site 4 Name4 Latitude4 Elevation4
Longitude5 Site 5 Name5 Latitude5 Elevation5
The output is shown with the original default field names, before a user
starts to add new values.
Although it may seem like a lot of work to create Document 3.6, the task is
greatly simplified by copying and pasting information for the rows. When
you access this page, the Tab key moves fromfield tofield but skips thefirst
column, which is justfixed text. The user of the page can change the default
values of all the input text boxes.
As shown earlier in this chapter, the t a b l e and f orm elements are used as
tools for organizing content in an HTML document. List elements provide
another way to impose formatting on related content. Table 3.2 gives a brief
summary of three kinds of lists.
Table 3.2 HTML list elements Description
De finition
(or glossary) Ordered
Unordered
List item
Glossary
HTML tags
<dl>…< / d l > Use
For a list that includes names and extensive descriptions
<ol> …< / ol > <ul >…< / u l > < l i > …< / l i > <dt>…< / d t > When a list of things needs to be
numbered For a list of“bulleted” items
Create list entry for <ul> or <ol>
< l i > Use unordered l i s t s f o r " b u l l e t e d " i t e m s . < / l i > < l i >
Use ordered l i s t s f o r numbered i t e m s . < / l i > < l i > Use defin i t i o
n l i s t s f o r l i s t s o f i t e m s t o be defined. < / l i >
</ul>
Here are t h r e e ways t o o r g a n i z e c o n t e n t in an HTML document:
<ol>
The use of these tags imposes a preset format for displaying list items. Blank
lines are inserted before and after the list, with no <br /> or <p>… <p> tags
required to separate the lists from other text in the document. For ordered
and unordered lists, the list items themselves are indented. For the definition
list, the items are not indented, but the“definitions” are. The contents of a list
item can include text formatting elements. For example, in Document 3.7,
the items in the definition list use the b element to display the item name in a
bold font. A list item can be an image, <img src="…" />, or a URL
reference, <a href ="…">.
Note the use of & l t; and > to display the < and > characters in the
document. (If you just type these characters, they will not be displayed on
the screen because HTML will try to associate them with tags and will
simply ignore them when it can’tfigure out what you meant.)
This page demonstrates the use of unordered, ordered, and definition lists.
Use unordered lists for “bulleted” items. Use ordered lists for numbered
items.
Use definition lists for lists of items to be defined.
1. Use a table.
2. Use a list.
3. Use<pre> ... </pre> tags.
Use this to display a list of glossary items and their definitions. ordered list
(<ol> )
Use this to display a numbered list.
unordered list (<ul> )
Use this to display a list of bulleted items.
There are some attributes associated with list elements that provide a little
more control over the appearance of lists.
start=" n "
Value : The integer n specifies the starting value of an ordered list. The
default value isstart="1" .
type = "…"
Values : For unordered lists: "disc" (the default value), "square" ,
"circle"
<html>
<title> T a b l e o f Contents f o r My B o o k< / t i t l e > <body>
<h2> Table o f Contents f o r My Book</h2> < o l >
<b><l i > Chapter O n e< / b > </ l i >
</ul>
</ol>
<li> S e c t i o n 1 . 2< / l i >
< l i > S e c t i o n 1 . 3< / l i >
</ol>
<b><l i > Chapter T wo< / b > < / l i >
< o l t y p e =" I " >
< l i > S e c t i o n 2 . 1< / l i >
< o l t y p e =" i " >
< l i > F i r s t T o p i c< / l i >
<l i > Second T o p i c< / l i >
< u l t y p e =" c i r c l e " >
< l i > < i > su b t o p i c 1< / i > < / l i >
< l i > < i > su b t o p i c 2< / i > < / l i >
</ul>
</ol>
<li> S e c t i o n 2 . 2< / l i >
< l i > S e c t i o n 2 . 3< / l i >
</ol>
<b><l i > Chapter T h r e e< / b > < / l i >
< o l t y p e =" I " >
< l i > S e c t i o n 3 . 1< / l i >
< o l t y p e =" i " >
< l i > F i r s t T o p i c< / l i >
<l i > Second T o p i c< / l i >
< u l t y p e =" c i r c l e " >
< l i > < i > su b t o p i c 1< / i > < / l i > < l i > < i > su b t o p i c 2</ i > < / l i > < l i > < i
> su b t o p i c 3< / i > < / l i > < / u l >
</ol>
<li> S e c t i o n 3 . 2< / l i >
<li> S e c t i o n 3 . 3< / l i >
< o l t y p e =" i " >
< l i > F i r s t T o p i c< / l i >
<l i > Second T o p i c< / l i >
</ol>
<li> S e c t i o n 3 . 4 </ l i >
</ol>
</ol>
</body>
</html>
Note that if this list were used for an online book, for example, each list item
could include a link to a URL or a hypertext link to another location within
the same document.
I. Section 1.1
i. First Topic
ii. Second Topic
subtopic 1
subtopic 2
<frameset> … </frameset>
Attributes : border , bordercolor , cols , frameborder ,
framespacing ,rows
Consider the following screen display. It is divided into three sections. The
upper left-hand corner contains a clickable image. The lower left-hand
corner contains links to other HTML documents. The right-hand column will
be used to display those documents. When this page isfirst accessed, a
“home page” document should be displayed.
Document 3.9a shows thefirst step in creating this page. Document 3.9a
(frameMain.htm)
<html>
<head>
< t i t l e >A si m p l e f ram eset d o c u m e n t < / t i t l e >
</head>
< f r a m e s e t c o l s= " 3 0 % , 70%" f ram eborder= "1">
< f r a m e s e t rows= "60%, 40%">
< f r a m e s r c = " f r a m e 1 . h t m " s c r o l l i n g = " n o " /> < f r a m e s
r c = " f r a m e 2 . h t m " />
</frameset>
< f r a m e name="homeFrame" sr c = " h o m e F r a m e .h tm " /> < / f r a
meset></html>
The f ram eset element is used to define the frames. In this case, the window
is divided into two columns. The left-hand column occupies 30% of the page
and the right-hand column occupies the remaining 70%. (In the graphic
displayed below, the proportions look different because the screen display
has been cropped to save space.) The line
where the asterisk is interpreted as “fill the remaining portion of the screen
with the right-hand column.” If the frame size is given as a number without
the %sign, it is interpreted as pixels rather than a percentage of the full
window. Setting this frame size to c o l s= " 2 0 0,* " will produce a left-side
frame that is always 200 pixels wide, regardless of the screen width and
resolution.
The left-hand column is further divided into two sub-windows. The top
window occupies the top 60% and the bottom window occupies the
remaining 40%. Each window is associated with a separate HTML
document, frame1.htm and frame2.htm. These windows could be given
names, but they don’t have to have names. The right-hand column is
associated with another HTML document, homeFrame.htm. This“home
frame” will be the destination for content that will be linked from the frame
in the lower left-hand corner. This frame needs a name to serve as a“target”
for the other documents that will be displayed here. The name can be
anything, but homeFrame is a self-explanatory and therefore reasonable
choice.
Documents 3.9b through 3.9d show the HTML code for each of the three
frames.
Document 3.9b (homeFrame.htm)
<html>
<head>
< t i t l e > M y Home F r a m e < / t i t l e >
</head>
<body b g c o l o r = " l i g h t g r e e n " >
< h 1 > < b l i n k > < f o n t col or= "maroon"><b>< i>Home page d i s p l a
y goes h e r e . < / i > < / b > < / f o n t > < / b l i n k > < / h 1 > < / b o d y >
</html>
<html>
<head>
<title>TitleFrame</title>
</head>
<body b g c o l o r = " p i n k " >
< f o n t si z e = " + 6 " c o l o r = " n a v y " > < c e n t e r > < b> < i >F r a
m e s < b r />Demo<br/>
<ahref="frameDescription.htm"/><img
src="frame.gif"
border="2"></i></b></center></a>
</font>
</body>
</html>
<html>
<head>
<title>GossipColumn</title>
</head>
<body b g c o l o r = " l i g h t b l u e " >
< f o n t si z e = " + 3 " >
L i n k s to o t h e r s t u f f . . . < b r />
<a h r e f =" g o s s i p . h t m " target= "hom eFram e" / > Gossip Column</a>
< b r />
<a h r e f = " p h o t o G a l l e r y . h t m " target= "hom eFram e" />
<html>
<head>
< t i t l e > H o w t h i s image was c r e a t e d . < / t i t l e >
</head>
<body>
T h i s image was c r e a t e d i n Windows′ P a i n t program . <a h r e f = " f
r a m e 1 . h t m " /> C l i c k here to r e t u r n . < / a > < / b o d y >
</html>
Document 3.9d, for the lower left-hand corner, contains links to several
other documents, each of which can be displayed in the right-hand window.
This is done by using the t a r g e t attribute, which links to homeFrame, the
namevalue given in Document 3.9a:
Document 3.9b contains the code for the home frame that is displayed when
the page isfirst accessed. (The b l i n k element, which causes text to blink on
and off, will be ignored by some browsers.) Document 3.9c, for the upper
left-hand frame, contains the clickable image, f r a m e .gif, with a border
drawn around it. Clicking on the image opens a link to descriptive file, f r a
m eD e sc r i p ti o n . htm (see Document 3.9e), to be provided by you. This
document will be displayed in the“Frames Demo” window (not opened in a
new window), and it should contain a link to return to frame1.htm:
HTML frames provide a great deal of flexibility for displaying content, but
there is one consequence that may not be immediately obvious. If you try
these examples on your own computer, you will see that only the main frame
document (frameMain.htm) is displayed as the URL link, regardless of
which document is being displayed in the right-hand column. So, you cannot
directly copy or bookmark the URL for a particular document. Accessing
the“view source” option on your browser will display the HTML code only
for frameMain.htm. If you wish to bookmark the“picture gallery” page, for
example, you cannot do so directly. You can display the page separately by
accessing the document separately:
This situation does not really hide all the code for these documents. You can
look at the frameMain.htm HTML code and then access separatelythe
homeFrame.htm, frame1.htm, and frame2.htm documents to examine their
HTML code.
Create a document that allows users to select observed cloud types from a
list of possibilities. More than one cloud type can exist simultaneously. The
categories are:
high altitude: Cirrus, Cirrocumulus, Cirrostratus mid altitude: Altostratus,
Altocumulus
low altitude: Stratus, Stratocumulus, Cumulus precipitation-producing:
Nimbostratus, Cumulonimbus A good way to organize this information is to
use a table within a form.
<html>
<head>
<title> C l o u d O b s e r v a t i o n s< / t i t l e >
< / h ea d >
<body b g c o l o r =" # a a d d f f " >
<h1> Cloud Observ ati ons</ h1>
<b> Cloud Observ ati ons < / b >
( S e l e c t as many c l o u d t y p e s as o b se r v ed .)
< b r />
<f or m >
<table>
<tr>
<t d><b> Hi gh</ b> < / t d >
<td>
<input t y p e =" c h ec k b o x"
name="high" v a l u e =" C i r r u s " />
C i r r u s< / t d >
<td>
<input t y p e =" c h ec k b o x" name="high"
v a l u e =" C i r r o c u m u l u s " / > Ci rrocum ul us < / t d >
<td>
<input t y p e = "c h ec k b o x" name="high"
v a l u e =" C i r r o s t r a t u s " / > C i r r o s t r a t u s
</td></tr>
<tr>
<td c o l sp a n=" 4 " > <hr noshade c o l o r =" b l a c k " />
</td></tr>
<tr>
< t d > <b> Mi ddl e</ b> < / t d >
<td>
<td>
<input t y p e =" c h ec k b o x" name="mid"
v a l u e =" A l t o c u m u l u s " />
A l t o c u m u l u s< / t d > < / t r >
<tr>
<td c o l sp a n=" 4 " > <hr noshade c o l o r =" b l a c k " />
</td></tr>
<tr>
< t d > <b> Low</ b></ t d>
<td>
<input t y p e =" c h ec k b o x" name="low" v a l u e =" S t r a t u s " />
S t r a t u s< / t d >
<td>
<td>
<input t y p e =" c h ec k b o x" name="low" v al ue="Cum ul us" /> Cumulus < / t d >
</tr>
<tr>
<td c o l sp a n=" 4 " > <hr noshade c o l o r =" b l a c k " /> < / t d > < / t r >
<tr>
< t d > <b> Rai n-Produci ng < / b > < / t d >
<td>
<td>
<input t y p e =" c h ec k b o x" nam e="r ai n"
v al ue="Cum ul oni m bus " / > Cumulonimbus
</td></tr>
</table>
</form>
</body>
In Document < / h t m l >
3.10, checkboxes
for the cloud types are organized into four groups, for high-, mid-, and low-
altitude clouds, plus rain-producing clouds. Withineach group, each
checkbox has a name associated with it.
Note that the names given to each checkbox in Document 3.10 are the same
as the text entered in the corresponding cell. This is only because these
names and text are reasonable descriptions of the cell contents. In general,
the text in the cell does not need to be the same as, or even related to, the
value of the name attribute of the checkbox.
Altostratus Altocumulus
Low
Nimbostratus Cumulonimbus
Create an application that maintains one or more “header lines” across the
top of a web page window while scrolling through a long text document.
Consider thisfile:
DRB Worcester PA
40.178 -75.3325
4030 5200
Mon day yr hr min sec EST PYR-1 PYR-2 T
7 1 2008 0 0 0 1 0.00031 0.00031 20.198
7 1 2008 0 1 0 1.000694444 0.00031 0.00031 20.174
7 1 2008 0 2 0 1.001388889 0.00031 0.00031 20.174 …
The file contains 1440 lines of data (24 hours times 60 minutes per hour for
July 1, 2008) with the date and time, the day and time converted to a
fractional Eastern Standard Time day (EST), data from two instruments,
PYR-1 and PYR-2, and air temperature in degrees Celsius. The instruments
measure incoming solar radiation.
For a file of this size, it might be convenient to be able to display these data
under afixed header that identifies the columns, in the same way that
spreadsheets allow creation of a“split window.” Documents 3.11a and 3.11b
show a very simple solution to this problem, using HTML frames.
<html>
<head>
< t i t l e > D i s p l a y pyranometer d a t a < / t i t l e >
</head>
< f r a m e s e t rows="10%, * " >
<title></title>
</head>
<body>
<fontface="courier">
T h i s is t h e h e a d e r . < b r />
mon day y r hr min
sec EST PYR-1 PYR-2
T<br /> < / f o n t >
</body></html>
The escape sequence allows the insertion of“white space” between
text to align headers. The f ram eset rows attribute allocates the top 10% of
the page to the header and the outputfile, pyranom eter .dat, is displayed in
the remainder of the page. For a display that is too long tofit in one window,
HTML automatically creates a scroll bar down the righthand side of the
window. A border has been retained under the top frame, just to make clear
how the page is divided, but it is optional; to remove the border, set the f ram
eset attributeborder= "0".
A simple modi fication of the f ram eset code in Document 3.11a would
allow listing a number of differentfiles in a left-hand column, each of which
could be displayed in the home page frame simply by clicking on thefile
name. To do this, the direct link to pyranom eter .dat in Document 3.11a
would be replaced with another name specified as the value of a t a r g e t
attribute in the reference to each document to be displayed:
THE END