14.2. Basic Frameset StructureA web page that is divided into frames is held together by a top-level frameset document. Frameset documents are fundamentally different from other HTML documents in that they use the frameset element instead of a body element. The frameset element may not contain any content, but instead defines and names some number of frames (or other framesets), arranged in rows and/or columns. Each frame is indicated with a frame element within the frameset. A frameset document contains a regular header portion (as indicated with the head element).
<frameset>...</frameset> Attributes
Nonstandard attributes
This is an example of a minimal frameset document in XHTML. The resulting frameset, shown in Figure 14-1, has two frames occupying two columns of equal width. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Simple Framed Document</title> </head> <frameset cols="*,*"> <frame src="/books/4/439/1/html/2/left.html" /> <frame src="/books/4/439/1/html/2/right.html" /> </frameset> <noframes> <body> <p>Your browser does not support frames.</p> <p><a href="left.html">Go to the left</a></p> <p><a href="right.html">Go to the right</a></p> </body> </noframes> </html> Figure 14-1. Basic frameset documentThe frameset document is displaying two external HTML documents, each in its own frame. The job of the frameset document is simply to build a framework that holds them together. It also includes the noframes element for providing alternative content for browsers that don't support frames. Take a look for a moment at the frameset source document. It begins with the DOCTYPE declaration that tells the browser to use the XHTML 1.0 Frameset DTD when rendering this file. Next is the html root element and an ordinary header containing the document's title.
This is the point at which a frameset document diverges from regular HTML documents. Instead of a body, it uses the frameset element that specifies that the document should display in two columns (cols) of equal width. The frameset is merely a container for two frame elements. The primary job of the frame element is to provide the URL of the document that should display in that frame. The example above has two frames. One pulls in a document called left.html and the other displays right.html. It is important to note that left.html and right.html are ordinary (X)HTML documents, each consisting of a head and body element. In other words, documents that are displayed within a frame are not frameset documents and do not need to use the Frameset DTD. They may be authored according to the Strict or Transitional DTDs. It is possible to display another frameset document in a frame; however, there are more efficient methods for nesting frames as discussed in the "Nesting Frames" section later in this chapter.
<frame /> Attributes
Nonstandard attributes
14.2.1. Alternate ContentThe sample frameset document contains one other element in addition to frameset. The noframes element contains content that will be displayed in browsers and devices that don't support frames; therefore, it is an important tool for ensuring the accessibility of framed documents.
<noframes> ... </noframes> Attributes
The noframes element should be placed after the frameset element. This is the noframes element provided in the example. <noframes> <body> <p>Your browser does not support frames.</p> <p><a href="left.html">Go to the left</a></p> <p><a href="right.html">Go to the right</a></p> </body> </noframes> The content of the noframes element might be just a few lines or an entire page of information. Ideally, the content of the noframes element is a complete alternative to the framed interface. It should include the entire content of the page within a body element. If the complete content is too large (in terms of byte size), opt for the list of descriptions and links instead. At minimum, noframes content should provide a brief description of each frame with a link to access the individual (X)HTML documents. Without links, the frameset document is a dead end to users and search engines. 14.2.2. Establishing Rows and ColumnsRows (horizontal frames) and columns (vertical frames) are established with the frameset element, using the rows and cols attributes, respectively. These attributes divide the frameset in a grid-like manner. Frames are filled from left to right for columns and from top to bottom for rows. The number of rows or columns in the frameset is determined by the number of size values provided. For example, to create a frameset with three columns, you write cols="25%,50%,25%" (or three other size values). In this case, the user agent creates a column for each of the provided measurements. Rows work in the same manner. Figure 14-2 shows a simple framed document divided into two equal-sized rows (on the left) and columns (right). Figure 14-2. Simple horizontal and vertical frameset layouts14.2.2.1. Specifying sizesFrame size can be listed in one of three ways:
14.2.2.2. Combining rows and columnsYou can specify both rows and columns within a single frameset, creating a grid of frames, as shown in Figure 14-3. When both cols and rows are specified for a frameset, frames are created left to right in each row, in order. Rows are created top to bottom. The order of appearance of frame elements within the frameset determines where their contents display. The order in which documents are displayed is demonstrated in Figure 14-3. Figure 14-3. Frameset with rows and columns14.2.3. Nesting FramesIt is possible to nest a frameset within another frameset, which means you can take one row and divide it into several columns (or, conversely, divide a column into several rows), as shown in Figure 14-4. Nesting gives you more page layout flexibility and complexity than simply dividing a frameset into a grid of rows and columns. Figure 14-4. Document with nested framesetsIn Figure 14-4, the top-level frameset specifies two columns. The first column is a frame 100 pixels wide. The second column (which occupies the remainder of the window) is filled with another frameset, this one with three rows. There is no technical limit on the number of levels that frames can be nested, only practical ones. If you nest frames, be careful to close each successive frameset or the document will not display correctly. |