home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


The PRE element marks text to be displayed with a fixed-width typewriter font. In particular, the PRE environment preserves the line breaks and space characters of the original text—this is the only HTML element that does so. PRE is therefore useful for presenting text that has been formatted for a fixed-width character display, such as a plain text terminal or for presenting program code or HTML markup examples that should be presented with a fixed-width font.

PRE supports the standard “generic” and “event-handler” attributes described earlier in this chapter. Note that the event handlers are only partially supported by Internet Explorer 4 and are not supported by Netscape Navigator 4.

PRE content is restricted to inline elements, with the exception of those inline elements that affect character font size or spacing (BASEFONT, BIG, FONT, SMALL, SUP, and SUB) or that insert arbitrary data (APPLET, IMG, OBJECT). Most browsers will allow these “forbidden” inline elements inside PRE, but the behavior is unpredictable.

An example of PRE is shown in Figures 6.15 and 6.16. Note the use of character highlighting. Character highlighting elements inside a PRE contribute zero character width.

Netscape Navigator supports two additional attributes, to control the rendering of PRE content. These attributes are defined in the following—note that these are nonstandard attributes and that equivalent formatting control is possible using style sheet instructions, as described in Chapter 7.

COLS=“number” (optional; Netscape Navigator 4 only) Specifies the maximum number of characters per line within the displayed PRE. If a line is longer than that specified by COLS, then the line is automatically wrapped. This attribute was introduced with Netscape Navigator 4 and does not work in earlier versions of the browser.
WRAP (optional; Netscape Navigator) Enables word wrapping of the PRE element content—the default is to not allow word wrapping and to have PRE content extend past the edge of the browser window if the line is larger than the display region. If WRAP is present, then the text is automatically wrapped at the edge of the display area.


TIP: PRE Element—Things to Avoid

You cannot use elements that define paragraph formatting within the PRE element. This means you cannot use <P>, <ADDRESS>, <Hn>, and so on. You also cannot use <BR>. You should also avoid tab characters, since different browsers interpret the size of a tab differently. Instead, you should use space characters to control horizontal spacing.



TIP: Useful Features of PRE

You can use the A (anchor) element to create hypertext anchors inside PRE. You can also use the character highlighting elements (STRONG, EM, etc.), although these highlighting elements may be ignored by the browser if appropriate rendering is not possible.



Figure 6.15 HTML example document illustrating the use of the PRE element. Figure 6.16 shows this document as displayed by the Netscape Navigator browser.

<HTML>
<HEAD>
<TITLE> Example of the PRE Element </TITLE>
</HEAD>
<BODY>
<H1 ALIGN=“center”> Example of the PRE Element</H1>
<P ALIGN=“center”> <B><I>The PRE element is often used to
include blocks of plain text.  For example you can use it
to include examples of typed code, such as the following
extract from a C program:</I></B>
<HR>
<PRE>
/* main program for fitting program */

extern int *sharv;
static char boggle[100];

main (int argc, char *argv)
double x_transpose, y_transpose, f_ack=2.3;
{
  ....
</PRE>
<HR>
<P> PRE is also useful for simple tables, as in:
<PRE>
   Item          Price     Tax    Total        Category

   fileserver    10000     300    10300           <A HREF=“cat_a.html”>A</A>
   disk drive      900      30      930           <A HREF=“cat_b.html”>B</A>
  <STRONG>transmission</STRONG>    4400     110     4510           C
  <EM>fertilizer</EM>      5500     100     5600           F
</PRE>
The markup tags take up no space: if you delete everything alt the tags
inside the <B>PRE</B>, you will see that all the columns line up. .
</BODY>
</HTML>


Figure 6.16  Display, by the Netscape Navigator 3 browser, of the document shown in Figure 6.15.

Fill-in Forms

HTML 3.2 supported interactive forms via the FORM element and the special elements INPUT, SELECT, OPTION, and TEXTAREA—these four elements define a form’s user input mechanisms and can only appear inside a FORM. The FORM element, in turn, specifies how the data collected by the form should be encoded and where the encoded data should be sent.

Advanced FORMS: BUTTON, FIELDSET, LABEL, LEGEND, and OPTGROUP

HTML 4 introduced five new form-content elements—BUTTON, FIELDSET, LABEL, LEGEND, and OPTGROUP, plus several new attributes, to support improved rendering of form content and better control over the input mechanisms. These elements are not supported by Netscape Navigator 4, but are partially supported by Internet Explorer 4. Since this chapter focuses on generally supported HTML markup, discussion of these newer elements is deferred to Chapter 7.

Page Layout with INPUT Elements

A designer has little control over the look of these different form input elements: In general, the FONT element affects text-labeled input elements (TYPE=“text,” “password,” buttons with text labels, or TEXTAREA elements) in very different ways, depending on the browser, as illustrated in Figures 6.17 and 6.18. Both Netscape Navigator 3 and Internet Explorer 3/4 ignore FONT or other text-highlighting elements surrounding form input elements (although, for some strange reason, the SUP element works with Navigator 3). With Navigator 4, however, these elements do affect the characteristics of the input elements, as shown at the bottom of Figure 6.18—note, however, that the browser miscalculates the size of the text input box when the FONT element changes the font face to a non-fixed-width font.

Alternatively, a cascading style sheet can set some of the display properties. An example is shown in Figures 6.19 and 6.20, where CSS rules are used to change the font size, family, and text color of text input elements and INPUT buttons. There are still important differences between the Netscape Navigator 4 and Internet Explorer 4 rendering of these elements, as shown in Figure 6.20: Only Internet Explorer can change the text color on buttons, while both browsers have trouble determining the correct width for text input regions. Note also that the default font for text input regions (INPUT or TEXTAREA) is Arial for Internet Explorer and Courier for Netscape Navigator.

FORM Element: Fill-in Forms

Usage: <FORM> ... </FORM>
Can Contain: ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, DL, FIELDSET, Hn, HR, [ISINDEX], MENU, NOFRAMES, NOSCRIPT, OL, P, PRE, TABLE, UL,

characters, character highlighting, A, APPLET, BASEFONT, BR, BUTTON, IFRAME, IMG, INPUT, LABEL, MAP, OBJECT, SCRIPT, SELECT, TEXTAREA
Can Be Inside: BLOCKQUOTE, BODY, CENTER, DD, DIV, FIELDSET, LI, NOFRAMES, NOSCRIPT, TD,TH,

APPLET, IFRAME, OBJECT
Attributes: CLASS, DIR, ID, LANG, STYLE, TITLE, standard event handlers,

onReset, onSubmit,
ACCEPT-CHARSET, ACTION, ENCTYPE, METHOD, NAME, TARGET


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.