Advanced Frame Layouts
In the following example, we'll start out by making a frame layout that sets up two rows:
- A top row that will act as the web page header and will always remain within the browser viewport.
- A bottom row that will be further split into two framed columns. The column on the left will contain the site menu and the column on the right will be the content area.
Now let's slap together the HTML coding to create it. It will require four HTML documents: one frameset document and three frame source documents.
We'll start with the frameset document...
<html>
<head>
<title>HTML Frames - An Advanced Frame Layout</title>
</head>
<frameset rows="20%,80%">
<frame src="header.htm">
<frameset cols="25%,75%">
<frame src="menu_adv.htm" name="menu">
<frame src="chapter1.htm" name="content">
</frameset>
</frameset>
</html>
Okay since there's alot going on up there, I've specially color-coded the HTML source to help you better understand what's going on. Here's the lowdown:
- The outer
<frameset>...</frameset>tags act as a container for everything else and use therows="20%,80%"attribute/value pair to split the page horizontally into two rows: a top row that spans 20% of the full height of the browser viewport and a bottom row that spans the remaining 80%. - The first
<frame>tag uses thesrc="header.htm"attribute/value pair to load theheader.htmfile into the top row. It's unlikely that a hyperlink will target this frame to load a new page so thenameattribute is omitted. - A second
<frame>tag that would normally be used to load a file into the bottom row is omitted and, in its place, we use an inner or nested set of<frameset>...</frameset>tags. This nested frameset uses thecols="25%,75%"attribute/value pair to split the bottom row into two columns: a left column that spans 25% of the full width of the browser viewport and a right column that spans the remaining 75%. - The two
<frame>tags inside the nested frameset each use thesrcattribute to loadmenu_adv.htmandcontent1.htminto the left and right columns respectively. The name attribute is used in each to permit hyperlinks to target the frame.
<frame> tag in a frameset document may be replaced by a new set of <frameset>...</frameset> tags. This nested frameset then splits the frame it represents into more framed sections.
Here's links to the three frame source documents used in our advanced frame layout. The links will display the pages outside of their frameset to allow you to study the source code of each (after clicking on the link, click on View » Source in your browser):
| header.htm | (The frameset loads this document into the top row.) |
| menu_adv.htm | (The frameset loads this document into the left column of the bottom row.) |
| chapter1.htm | (The frameset loads this document into the right column of the bottom row.) |
Inline Frames
You can actually create a little framed section right in the middle of a standard web page and have it load and display a separate html document inside. This is known as an inline frame and it is easily created using the
<iframe>...</iframe> tags.Here's an inline frame displaying chapter 1 of H. G. Wells War of the Worlds:
As you can see it performs just like a mini web page (complete with scroll bars).
Here's the source code used to create it:
<iframe src="chapter1.htm" name="subwindow" width="400" height="200"></iframe>
The
<iframe> start tag requires at least the src attribute and can also use other attributes to enhance the inline frame's usability and appearance. These are outlined below:
src="file name"~ Use thesrcattribute to specify which HTML document is to be loaded into the inline frame. The value of thesrcattribute can be just the file name (relative addressing) or a full-blown URL (absolute addressing).name="any name"~ Use thenameattribute to act as a target for hyperlinks to use to load other documents into the inline frame. (See Creating Hyperlinks for Frames for more information.)width="percentage or pixels"~ Using thewidthattribute, you can explicitly set the width of your inline frame. You may define either a fixed width in pixels or a relative width which will size your inline frame according to a percentage of the available space (typically the entire width of your web page). Hence awidth="400"attribute/value pair will set the width of your inline frame to 400 pixels. Awidth="50%"attribute/value pair will set the width to 50% of the available space.height="percentage or pixels"~ Using theheightattribute, you can explicitly set the height of your inline frame. You may define either a fixed height in pixels or a relative height which will size your inline frame according to a percentage of the available space (typically the entire height of your web page). Hence aheight="200"attribute/value pair will set the height of your inline frame to 200 pixels. Aheight="50%"attribute/value pair will set the height to 50% of the available space. (NOTE: It'll probably be easier to just use pixels to set the height.)
Okay so now that we know all about basic and advanced frame layouts, let's learn how to create hyperlinks in frames...
| <~ BACK | TOP | NEXT ~> |
