HTML: The Definitive Guide

Previous Chapter 10 Next
 

10.4 Frame Contents

A frame document contains no displayable content, except perhaps a message for nonframe enabled browsers (see <noframes> later in this chapter). Rather, <frame> tags inside the one or more <frameset> tags, which encapsulate the contents of a frame document, provide URL references to the individual documents that occupy each frame. [<noframes>, 10.5]

The <frame> Tag

The <frame> tag appears only within a <frameset>. Use it to set, via its associated src attribute, the URL of the document content that initially gets displayed inside the respective frame.

Frames are placed into a frameset column by column, from left to right, and then row by row, from top to bottom, so the sequence and number of <frame> tags inside the <frameset> tag are important.

Netscape displays empty frames for standalone <frame> tags without an associated src document attribute and value and those trailing ones in the frameset that do not have an associated <frame> tag. Such orphans, however, remain empty; you cannot put content into them later, even if they have a target ``name'' for display redirection (see the name attribute below).

The src attribute

The value of the src attribute for the <frame> tag is a URL of the document that is to be displayed in the frame. There is no other way to provide content for a frame. You shouldn't, for instance, include any <body> content within the frame document; Netscape will ignore the frame tags and display just the contents of a <body> tag if it comes first, or vice versa.

The document referenced by the src attribute may be any valid HTML document or displayable object, including images and multimedia. In particular, the referenced document may itself be composed of one or more frames. The frames are displayed within the referencing frame, providing yet another way of achieving complex layouts using nested frames.

Since the source may be a complete HTML document, all the features of HTML apply within a frame, including backgrounds and colors, tables, fonts, and the like. Unfortunately, this also means that multiple frames in a single browser window may conflict with each other. Specifically, if each nested frame document (not a regular HTML document) has a different <title> tag, the title of the overall browser window will be the title of the most recently loaded frame document. The easiest way to avoid this problem is to ensure that all related frame documents use the same title.

The name attribute

The optional name attribute for the <frame> tag labels that frame for later reference by Netscape's target attribute for the hypertext link anchor <a> tag. This way, you can alter the contents of a frame differently from the one that contains the link. Otherwise, like normal browser windows, hypertext-linked documents replace the contents of the source frame. We discuss names and targets in greater length later in this chapter. [target for <a>, 10.6.1]

The value of the name attribute is a text string enclosed in quotes.

The noresize attribute

Even though you may explicitly set their dimensions with attributes in the <frameset> tag, users can manually alter the size of a column or row of frames. To suppress this behavior, add the noresize attribute to the frame tags in the row or column whose relative dimensions you do not want users fiddling with. For a two-by-two frame document, a noresize attribute in any one of the four associated frame tags will effectively freeze the relative proportions of all the frames, for example.

The noresize attribute is especially useful for frames that contain fixed images serving as advertisements, a button bar, or a logo. By fixing the size of the frame to contain just the image and setting the noresize attribute, you guarantee that the image will be displayed in the intended manner and that the remainder of the browser window will always be given over to the other frames in the document.

The scrolling attribute

Netscape normally displays vertical and horizontal scrollbars with frames whose contents exceed the allotted window space. If there is sufficient room for the content, the scrollbars disappear. The scrolling attribute for the <frame> tag gives you explicit control over whether or not the scroll bars appear or disappear.

With scrolling="yes", Netscape adds scroll bars to the designated frame even if there is nothing to scroll. If you set the scrolling attribute value to ``no,'' scrollbars will never be added to the frame, even if the frame contents are larger than the frame itself. The value auto works the same as if you didn't include the scrolling attribute in the tag; Netscape adds scrollbars as needed.

The marginheight and marginwidth attributes

Netscape normally places a small amount of space between the edge of a frame and its contents. You can change those margins with the marginheight and marginwidth attributes, each including a value for the exact number of pixels to place around the frame contents.

You cannot make a margin less than one pixel, or make it so large there is no room for the frame contents. That's because these attributes, like most other HTML ones, advise; they do not dictate to the browser. If your desired margin values cannot be accommodated, Netscape ignores them and renders the frame as it best sees fit.


Previous Home Next
Frame Layout Book Index The <noframes> Tag