To Temple College Class  logo R. Craig Collins > Web Page Design > Frames

Frames © R. Craig Collins, 2005/13
To review complex frame concepts, click here.
To code a complex frame, click here.


Note: NVu/Kompozer doesn't do frames
Dreamweaver, after CS 5, can open them, but can't create them.
Earlier Dreamweaver that could create frames often messes up and uses absolute addresses instead of relative addresses, and creates pages to put in the frame rather than letting you choose an existing page.
For that reason I offer frame templates to help you with your labs.

   • A frameset carves a browser window in to spaces, either columns or rows
        • A frameset can contain a frame, which holds a web page
           or
        • another frameset

Framesets and Frames are a way of opening multiple web pages in the same browser window
,
such as in two rows,

Page1


Page2


or, a more complex frame set where you mix columns and columns divided into rows.
To review complex frame concepts, click here.
To code a complex frame, click here.


  1. This left side could be used as a table of contents
  2. This top frame is information you wish to always be visible at the top of a page
  3. This would be the main content you wish to display
  4. This bottom frame is information you wish to always be visible at the bottom of a page

This "Step By Step" consists of two parts.
In the first part we explain how to create a "simple 2 row frame" frameset page, one that is divided up into JUST rows or JUST columns, but not both. A good example of this would be a home page that has a "toolbar" that takes you to different portions of a Web site.

The second part of this page explains how to create a complex frameset page. Once you've learned how to create simple frameset pages, it's actually quite straightforward to create a "complex " frameset page; one that can have both columns and rows. The code for the complex frame is below.
To jump to complex frame concepts, click here.
To jump to code for a complex frame, click here.


Creating a Simple Frameset Page

Step 1: Decide how many rows or columns you want.

Remember, framesets and frames are a way of dividing the browser's screen into different independent portions. In the "simple" case, you will be dividing the screen into only columns or rows. For this example, we'll create a page with two rows.

Row 1 (20%)


Row 2 (80%)


Step 2: Create the pages that make up the rows or columns.

The most important thing to remember about frames and framesets is that a frameset carves the browser up to displays more than one HTML page. These carved up spaces normally contain a frame... the frame is what holds one of the web pages to display.

If you have a frameset page with two frames in it, three HTML files are needed: one for each of the frames, and one that describes how the frameset will be laid out.

In this case, we'll say that you've created two HTML pages, row1.htm and row2.htm. The former will be shown in the top frame, and the latter will be shown in the bottom frame.


Step 3: Create the frameset page.

The next step is to create the frameset page that describes how the page is laid out. Here's the HTML for our frameset page:

<HTML>
<!--Note: no body tag is required... the web pages that are opened within the frame provide that info-->
<!--Note: later you we'll add back the head tag to pass a title, etc.-->

<FRAMESET ROWS="20%, *">
     <FRAME SRC="row1.htm">
     <FRAME SRC="row2.htm">
</FRAMESET>

</HTML>

Framesets divide the web pages into placeholders.
Frames fill the placeholders with a web page.

The number of values that follow the ROWS= or the COLS= determine how many rows or columns will be created.
The values assigned determine how big the row or column is... either in pixels or as a percentage of the screen.
The * used above means "what ever is left over."

Thus row one will be 20% of the available screen, and row two will be what ever is left, in this case 80%.

When viewed, this page will be divided into two rows, showing the two files that you created: row1.htm and row2.htm.

To create a page with two columns instead of two rows, simply use COLS instead of ROWS in the FRAMESET tag:

<FRAMESET COLS="20%, *">



Step 4: Set the relative sizes of the rows or columns.

There are four ways to tell a browser how tall to make a row:

  1. Number of pixels. To make the first row 200 pixels tall, use ROWS="200, *".
  2. Percentage of screen height, as in ROWS="20*, *"
  3. Use "*", meaning "whatever is left over." The above examples also use this method.
  4. Use "n*", where n is a number. This means "n parts of what's left over." Thus ROWS="*, 2*" makes two rows where the first one is 1/3 the height of the screen and the second is 2/3 the height of the screen. And ROWS="100, 2*, *" creates three rows: one 100 pixels tall, one that takes up 2/3 of the remaining space, and one that takes up the last 1/3.

Step 5: Decide where the links should go.

Because each frame is a separate browser, clicking a link in one of the frames will go to a new page in that frame. In some cases that may not be what you want.

It's possible to create a link that, when clicked, makes a new page show up in another frame. To do this, you need to name the frames, just as you named your anchors to make bookmarks.:

<HTML>

<FRAMESET ROWS="20%, *">
     <FRAME SRC="row1.htm" name="firstrow">
     <FRAME SRC="row2.htm" name="secondrow">
</FRAMESET>

</HTML>

Let's say you want to be able to click a link in the top frame and have a new page come up in the bottom frame.
To do this, place the following in row1.htm:

<A HREF="newpage.htm" TARGET="secondrow">Click here to see "newpage.htm" in the bottom frame</A>

The TARGET attribute causes the link to be opened in the bottom frame.

If you want to be able to click a link and have a new page fill the window (replacing the frameset), use TARGET="_top" as follows:

<A HREF="newpage.htm" TARGET="_top">Click here to see "newpage.htm" take up the whole window</A>

And if you want the page to come up in an entirely new Internet Explorer window, use TARGET="_BLANK" as follows:

<A HREF="newpage.htm" TARGET="_BLANK">Click here to see "newpage.htm" come up in a new window</A>

Note: This works even on pages that do not have frames. To avoid cluttering the user's desktop with windows, this feature should be used sparingly.

To skip to complex frame concepts, click here.
To kip to the code for a complex frame, click here.


frame


Step 6: OPTIONAL: Do you want users to be able to resize and scroll?

If you do not want users to be able to resize a frame, add a NORESIZE attribute to the FRAME tag:

<HTML>

<FRAMESET ROWS="20%, *">
     <FRAME SRC="row1.htm" NORESIZE>
     <FRAME SRC="row2.htm">
</FRAMESET>

</HTML>

If you do not want a frame to have scrollbars, add a SCROLLING attribute to the FRAME tag and set it to "NO" to disable the scrollbar:
<HTML>

<FRAMESET ROWS="20%, *">
     <FRAME SRC="row1.htm" NORESIZE>
     <FRAME SRC="row2.htm" SCROLLING="NO">
</FRAMESET>

</HTML>

Both of these settings are useful when creating toolbars.

To skip to complex frame concepts, click here.
To skip to the code for a complex frame, click here.


frame


Step 7: OPTIONAL: Do you want 3-D borders around your frames?

By default, frameset pages have 3-D borders between the frames. For a completely seamless look, change the FRAMESET tag to the following:

<FRAMESET ROWS="20%, *" FRAMEBORDER="0" FRAMESPACING="0">

This instructs the browser to turn off all 3-D borders between frames and to place the frames right up against each other. This feature, which was unique to Internet Explorer, is called borderless frames.

To learn how to place a colored or textured border between your borderless frames, see Advanced Topics below.

When using borderless frames, it's often helpful to be able to position a frame's contents directly at the top left corner of the frame, instead of a few pixels down and to the right, as is the default.

To do this, change the individual frame page (in this case, row1.htm or row2.htm) so its BODY tag includes the following:

<BODY TOPMARGIN="0" LEFTMARGIN="0">

To skip to complex frame concepts, click here.
To skip to the code for a complex frame, click here.


frame


Congratulations!

That's all it takes to create a simple frameset page of your own. The next section explains how to make complex framesets, which can be divided into both columns and rows.



Creating a Complex Frameset Page

Now that you know how to create simple frameset layouts, it's very straightforward to make complex ones. A complex frameset is just a simple frameset, but some of the carved spaces are filled with framesets, instead of frames.

IMPORTANT CONCEPT: A FRAMESET carves space that can be filled with a frame, or another FRAMESET..

Let's say we want to create a page that has an index on the left and three frames of content on the right:



To do this, we create a frameset with two columns. The first column will contain frame 1, and the second will contain another frameset that holds frames 2 through 4. Here's the HTML:

<HTML>
<FRAMESET COLS="20%, *">

The first column is just a single frame:

Less thanFRAME SRC="frame1.htm"Greater than

But for the second column, instead of using another FRAME tag, we insert a FRAMESET tag with three rows.

<FRAMESET ROWS="20%, *, 20%">
   Less thanFRAME SRC="frame2.htm" name="topframe"Greater than
   Less thanFRAME SRC="frame3.htm" name="middleframe"Greater than
   Less thanFRAME SRC="frame4.htm" name="bottomframe"Greater than
</FRAMESET>

Then we close the FRAMESET and HTML tags, and we're done.

</FRAMESET>
</HTML>

Thus, by "nesting" one frameset inside another, complex frame layouts can easily be built from simple ones.

We could have created the same layout by using two FRAME tags and pointing the second FRAME tag to a separate file that was itself a frameset. The above syntax, in which we can insert a FRAMESET block instead of a FRAME tag, is actually a shorthand that reduces the number of files needed by one.

There's one case in which you don't want to use the shorthand: when you want to click a link in frame 1 and have a page come up that replaces frames 2, 3, and 4. In that case, you would do it the longer way, giving the second frame a name and using a hrefaddress" TARGET="name of right-hand frame"> to replace the contents of that frame.

To skip to the code for a complex frame, click here.


frame


OPTIONAL Advanced Techniques


Making Frameset Pages Visible in Browsers that Don't Support Frames

Since frameset pages usually contain no content, just a set of FRAMESET and FRAME tags, they tend to not show up at all in browsers that don't support frames. Fortunately, the frames standard provides an easy way to provide content for non-frame browsers. Before the ending </HTML> , insert

<NOFRAMES>
Replace this with content to be displayed if browser does not support frames
</NOFRAMES>

<HTML>

<FRAMESET ROWS="20%, *">
Less thanFRAME SRC="row1.htm"
Greater than
Less thanFRAME SRC="row2.htm"
Greater than
</FRAMESET>

<NOFRAMES>
Welcome to my home page! Click below to see my vacation photos...
etc.
</NOFRAMES>

</HTML>

Internet Explorer and other browsers that support frames will ignore everything between <NOFRAMES> and </NOFRAMES>. Browsers that do not support frames will ignore the frames and display everything between the NOFRAMES tags.


Placing a Colored or Textured Border Between Frames

With many HTML 4 compliant browsers, you can not only turn off the 3-D, you can also specify that the borderless frames should be a particular distance apart. Because this allows the background of the frameset page to show through, if your frameset page has a background color or image the effect is that of a colored or textured border between the frames.

<HTML>
<BODY BACKGROUND="woodgrain.gif">

<FRAMESET ROWS="20%, *" FRAMEBORDER="0" FRAMESPACING="20">
<FRAME SRC="row1.htm">
<FRAME SRC="row2.htm">
</FRAMESET>

</BODY>
</HTML>

The code above places a 20-pixel border between the two rows of the frameset. Because the author has specified a background graphic (woodgrain.gif), there will now appear to be a 20-pixel-wide textured border between the frames. (To use a background color instead of a background image, use BODY BGCOLOR=color name or value.)

Coding the example frame


Coding my sample:

It is always a good idea to draw out your design

Table of Contents

Book the First: Recalled to Life

Chap 1
Chap 2
Chap 3
Chap 4
Chap 5
Chap 6
A Tale of Two Cities
IT WAS the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way- in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only.

There were a king with a large jaw and a queen with a plain face, on the throne of England; there were a king with a large jaw and a queen with a fair face, on the throne of France. In both countries it was clearer than crystal to the lords of the State preserves of loaves and fishes, that things in general were settled for ever. ...
This page brought to you buy your local Realtor©

Modern HTML standards include a DOCTYPE to tell the browser to expect the frames... I have included one below .
(NOTE, the code for the left web pages that open in the frame is under the frame code, below.)


Click here to actually see this frame implemented

Code for frame
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0  Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
 
<HTML> 
<FRAMESET cols="200, *">   
<FRAME name="side" SRC="side.htm">  
<FRAMESET ROWS="20%, 70%,*">     
<FRAME name="top" SRC="top.htm">     
<FRAME name="middle" SRC="middle.htm">     
<FRAME name="bottom" SRC="bottom.htm">  
</FRAMESET>
</FRAMESET> <!-- optional noframes tags could go here--> </HTML>

Code for the side page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Side of Frame</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#0000FF" text="#FFFFFF" link="#FFFFFF">
Table of Contents
<p>Book the First: Recalled to Life</p>
<p>
a hrefmiddle.htm" target="middle">>Chap 1</a><br> a hrefmiddle2.htm"target="middle">Chap 2</a><br> a hrefmiddle3.htm"target="middle">Chap 3</a><br> a hrefindex.html"target="middle">Index in middle</a><br> a hrefframes.html" target="_blank">Index in new</a><br> a hrefindex.html" target="_top">Whole Index</a>
</p> </body> </html>