Creating Documents with Frames (<frameset>)

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:

AttributeDescription
classGives the style class of the element.
colsSets the number of columns (vertical framed bands) in the frameset.
dirSets 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.
idUse the ID to refer to the element; set this attribute to a unique identifier.
langSpecifies the base language used in the element. Applies only when the document is interpreted as HTML.
rowsSets the number of rows (horizontal framed bands) in the frameset.
styleIs an inline style indicating how to render the element.
titleContains the title of the element.
xml:langSpecifies 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.

Creating Individual Frames (<frame>)

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:

AttributeDescription
classGives the style class of the element.
dirSets 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.
frameborderSets whether borders enclose the frame. In Netscape, you set this attribute to yes (the default) or no; in Internet Explorer, you set it to 1 (the default) or 0 (no border).
idUse the ID to refer to the element; set this attribute to a unique identifier.
langSpecifies the base language used in the element. Applies only when the document is interpreted as HTML.
longdescSpecifies the URI for a long description of the frame contents, which may include markup.
marginheightSets the height of the top and bottom margins used in the frame.
marginwidthSets the width of the right and left margins used in the frame.
nameSets the name of the frame, which you can use as target destinations for <a>, <area>, <base>, and <form> elements.
noresizeIndicates that the frame may not be resized. The default is that frames may be resized by dragging the border.
scrollingSets scrollbar action; possible values are auto, yes, and no.
srcIs required. Holds the URI of the frame document.
styleIs an inline style indicating how to display the element.
titleContains the title of the element.
xml:langSpecifies the base language for the element when the document is interpreted as an XML document.

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.

Figure 17.5. Displaying XHTML frames.


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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.180.161