home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeHTML & XHTML: The Definitive GuideSearch this book

11.2. Frame Tags

You need to know only three tags to create a frame document: <frameset>, <frame>, and <noframes>. In addition, the HTML 4 and XHTML standards provide the <iframe> tag, which you may use to create inline, or floating, frames.

A frameset is simply the collection of frames that make up a browser's window. Column- and row-definition attributes for the <frameset> tag let you define the number and initial sizes for the columns and rows of frames. The <frame> tag defines which document -- HTML or otherwise -- initially goes into the frames within those framesets and is where you may give the frame a name to use for document hypertext links.

Here is the HTML source that was used to generate Figure 11-1:

<title>Frames Layout</title>
<frameset rows="60%,*" cols="65%,20%,*">
  <frame src="frame1.html">
  <frame src="frame2.html">
  <frame src="frame3.html" name="fill_me">
  <frame scrolling=yes src="frame4.html">
  <frame src="frame5.html">
  <frame src="frame6.html">
    Sorry, this document can be viewed only with a 
    frames-capable browser.
    <a href = "frame1.html">Take this link</a>
    to the first HTML document in the set.

Notice a few things in the simple frame example and its rendered image (Figure 11-1). First, the order in which the browser fills the frames in a frameset goes across each row. Second, Frame 4 sports a scrollbar because we told it to, even though the contents may otherwise fit without scrolling. (Scrollbars automatically appear if the contents overflow the frame's dimensions, unless explicitly disabled with the scrolling attribute in the <frame> tag.) Section 11.4.1, "The <frame> Tag"

Another item of interest is the name attribute in one of the frame tags. Once named, you can reference a particular frame as the location in which to display a hypertext-linked document. To do that, you add a special target attribute to the anchor (<a>) tag of the source hypertext link. For instance, to link a document called new.html for display in Frame 3, which we've named "fill_me", the anchor looks like this:

<a href="new.html" target="fill_me">

If the user chooses the link, say in Frame 1, the new.html document will replace the original frame3.html contents in Frame 3. Section 11.7.1, "The target Attribute for the <a> Tag"

Finally, although Netscape and Internet Explorer both support frames, it is possible that users with some other browser will try and view your frame documents. That's why each of your key frame documents should provide a back door to your document collection with the <noframes> tag. Frame-capable browsers display your frames; non-frame-capable browsers display the alternative <noframes> content.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.