You use the <frameset> element when you want to display frames in a document. The <frameset> element replaces the <body> element in such documents; in XHTML 1.0, that means you use the XHTML 1.0 Frameset DTD. This element is supported in XHTML 1.0 Frameset only. The <frame> and <frameset> elements are not supported in XHTML 1.1; the XHTML 1.1 DTD does not makes any mention of these elements or of frames at all, and these elements are specifically listed as unsupported in XHTML 1.1. Why aren't frames supported in XHTML 1.1? They're not supported because the W3C expects style sheets to handle the presentation techniques that you use frames for today; whether the Web community will ultimately accept that is anyone's guess.
Here are the attributes of this element:
Attribute | Description |
---|---|
class | Gives the style class of the element. |
cols | Sets the number of columns (vertical framed bands) in the frameset. |
dir | Sets the direction of directionally neutral text . You can set this attribute to ltr, for left-to-right text, or rtl, for right-to-left text. |
id | Use the ID to refer to the element; set this attribute to a unique identifier. |
lang | Specifies the base language used in the element. Applies only when the document is interpreted as HTML. |
rows | Sets the number of rows (horizontal framed bands) in the frameset. |
style | Is an inline style indicating how to render the element. |
title | Contains the title of the element. |
xml:lang | Specifies the base language for the element when the document is interpreted as an XML document. |
This element supports no XHTML events.
You use the <frameset> element and the XHTML frameset DTD to format a page into frames. This element takes the place of the <body> element in documents that display frames. To create the frames themselves, you use the <frame> element.
To format the display into frames, you use the rows or cols attribute of the <frameset> element. You indicate the number or rows or columns that you want to use by giving their heights or widths in a comma-separated list. To specify those heights or widths, you can give pixel measurements or a percentage measurement (such as "40%") to request a percentage of the available display area. If you use an asterisk, the browser will try to give you the remaining display area; for example, cols="200, *" creates one vertical frame of 200 pixels and a second vertical frame filling the remainder of the display area. I recommend using percentage measurements rather than pixel measurements because the user may resize the browser window.
For example, here's how I create two columns—that is, two vertical frames—each of which takes up half the available width (note that I'm using the XHTML 1.0 frameset DTD):
<?xml version="1.0"?> <!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> Using XHTML Frames </title> </head> <frameset cols = "50%, 50%"> . . . </frameset> </html>
So how do you actually create the frames that should be displayed? Take a look at the next topic.
You use the <frame> element to create an individual frame. This element is an empty element, and you use it inside the <frameset> element. It's supported in XHTML 1.0 Frameset only. This table lists its attributes:
This element does not support any XHTML events.
You can use the <frame> element inside a <frameset> element to create a frame. This element exists so that you can specify the document that is displayed in a URI. That's the one required attribute in this element—src, which holds the URI of the document that the frame is to display.
For example, here's how I might display two frames, placing the contents of the document frame1.html in one, and the contents of frame2.html in the other:
<?xml version="1.0"?> <!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> Using XHTML Frames </title> </head> <frameset cols = "50%, 50%"> <frame src="frame1.html" /> <frame src="frame2.html" /> </frameset> </html>
Here's frame1.html:
<?xml version="1.0"?> <!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> Using XHTML Frames </title> </head> <body bgcolor=red> <h1> <center> This is frame 1. </center> </h1> </body> </html>
And here's frame2.html:
<?xml version="1.0"?> <!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> Using XHTML Frames </title> </head> <body bgcolor=cyan> <h1> <center> This is frame 2. </center> </h1> </body> </html>
The result of this XHTML appears in Figure 17.5.
That's all it takes to create and display frames in XHTML, but bear in mind that the W3C has apparently targeted frames for extinction. Will style sheets be capable of taking over what frames do today? That remains to be seen. I'll take a look at handling style sheets now.
18.226.180.161