Click here to bookmark this site! Home | Contact | About | Site Map  
 

Quick Menu

Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24


Beginner

 

22. Web Page Frames

You likely have seen web pages that use frames. You would have seen them on web site pages and possibly not even realized.

Frames make the page you are viewing up out of up to 2, 3 or even more separate HTML pages all placed into frames and are completely independent of each other to give the appearance of 1 whole page.

The advantage is clear for web sites that contain navigation links to many other web pages. This allows control of the site in the left frame with the navigation and is always visible and the content to be displayed in the right frame.

Hyperlinks have special uses within framed web pages. Sometimes a hyperlink in one frame will replace the content in that frame with new content. Other times a hyperlink will load new content in another frame. And you can have links that will completely replace all of the frames with a new page. This is actually the same kind of link "targeting" we learned in lesson 21.

Click to see a brief EXAMPLE of how frames work.

You can have your frames set up in many different ways.

Google

Web
Eazy HTML

Site Stats

There are 6 users online
click to see where

149,243 total unique visitors
485,914 total pageviews
49 visitors in the last 24 hours
38 total visitors today
123 pageviews today
This page has been visited 3,691 times

get this script
Most users online at once:
63 on 01/18/2010

Valid CSS!

Valid XHTML 1.0!

WHAT ARE THE DISADVANTAGES OF FRAMES
As a working web designer; you must keep track of more HTML documents. When you convert a document to a framed design, a single HTML file might end up as 3, 4, or maybe 12 separate HTML files. For the viewer, a framed page can take longer to load and display. Poorly designed, framed web pages look crowded and sometimes amateurish. Frames will also make it difficult to print paper copies of the entire page. Finally, you may be restricting some users from your site if they have a web browser that does not support frames (most browsers since NetScape 2.0 and Internet Explorer 3.0 display frames)

WHEN SHOUD I USE FRAMES?
The content should really tell you. If there is a need to keep certain elements visible on a web page at times while changing the content of other areas, frames can be very effective. You can get a better sense by examining other web sites and see how they use frames.

FRAME BASICS
A web page that consists of frames has a "master" HTML document, that we'll call the "blueprint" for the layout, which defines the frame sets, or the arrangement of the framed areas on the page. This is the document that loads the frame structure and the one that represents the URL for the framed page.

Image of frame designs

Each of the sub-divided areas you see in the diagrams above will be associated with its own separate HTML file that defines what goes into that particular box. Therefore, your first step should be to sketch out how you want the page to look like after it's been divided up and how much relative space each area needs.

Looking at the sketches above, example 1 is made of 2 columns and example 2 contains 2 rows. Example 3 can be seen as two rows, with the second row containing two columns.

Example 6 can be seen as three rows, where the middle row has two columns. And so is Example 5 except that first row is the one with two columns.

And Example 7!!! OK here goes, it starts as three Rows, The first row is then split into 2 columns, and the second columns is the split into 2 rows. Then the second row is split into 2 columns as well, the first column is split into 2 rows the second columns is left as a whole.. The third row is left as is. If you would like to view what the source code for this would look like then CLICK HERE and if you want to view the page then CLICK HERE.

So each collection of rows and columns makes up an HTML frame set and the HTML "blueprint" document for the framed page can have one or more frame sets. The HTML format is slightly different from the ones we've created so far-- it lacks a set of <body>...</body> tags. When creating frames you must remember that there are no body tags in the document, If you put them in your document will not render properly. This make sense from what we learned way back in lesson 1 since none of the frame set definitions actually specify the content that appears on the web page (normally everything inside the <body>...</body> tags,) but rather the structure of how they are arranged.

Below is a generalized format for a "blueprint" HTML document:

<html>
    <head>
      <title>Title of this Whole Page</title>
     </head>
    
      <frameset rows/cols="X,Y,...Z">
    	<frame src="frame_source1.html">
    	<frame src="frame_source2.html">
    	    :
    	    :
    	<frame src="frame_sourceN.html">	    
      </frameset>
      <noframes>
      This is what someone would see who does not have a web
      browser that can display frames.
      </noframes>
  </html>

So each of the frame set tags defines either a set of rows or columns (either <framset rows=...> or <frameset cols=...>). The numeric values of X, Y, and Z indicate the amount of screen area each row/column will occupy, either in a percentage of the browser window size, or an absolute number of pixels. The number of items in this list defines the number of rows or columns. For each row/column specified, this dimension is associated with the HTML document specified in the subsequent list of <frame src=...> tags.

The most challenging part of designing a framed web site from scratch is developing the layout structure of your main document. Now Remember, the numbers that you provide in the <frameset...> tag, indicate the number of and the dimensions of a set of rows or columns within your page. You can use either percentages (i.e. ROWS=10%, 30%, 60%) or absolute numbers of screen pixels (i.e. COLS=100, 300, 80, 200). The choice of this depends on whether the design requires a particular frame to always be the same size (use absolute pixels) or if it can scale to the proportions of the viewer's browser window (use percentages).

This is how we might write up Example 1

<html>
    <head>
      <title>A Two Row Framed Page</title>
     </head>
  
      <frameset cols="15%,85%">
    	<frame src="frame_source1.html">
    	<frame src="frame_source2.html">    
      </frameset>
      <noframes>
      This is what someone would see who does not have a web
      browser that can display frames
      </noframes>
  </html>

You can easily modify this document to create the layout of example 2 by changing cols= to rows=. In either of these two cases, if the viewer shrinks or expands their web browser window, the areas of the frames will adjust according to the percentages of space provided. If you wanted to fix the frame to an absolute width, say in example 2 to have the top row to always be 100 pixels high, you would change the tag to read:

   <frameset rows="100,*"
Ahoy!! The "*" or "wildcard" value for the dimension tells the web browser to use the remaining space that is left for the bottom row.

Now let's look at a more complex frame document, the one that would define example 7:


<html>
<head><title></title></head>
<!-- Sets up the initial 3 rows -->
  <frameset rows="100,*,100">
    <!--Row 1 - Splits the row into 2 coloumns -->
    <frameset cols="25%,75%">
      <frame src="a.htm" name="framea">
    <frameset rows="50%,50%">
      <frame src="b.htm" name="frameb">
      <frame src="c.htm" name="framec"">
    </frameset>
  </frameset>
  <!-- Row 2 Splits into 2 columns -->
  <frameset cols="50%,50%">
    <frameset rows="50%,50%">
      <frame src="d.htm" name="framed">
      <frame src="e.htm" name="framee">
    </frameset>
   <frame src="f.htm" name="framef">
  </frameset>
  <!-- Row 3 Stays as is -->
 <frame src="g.htm" name="frameg">
</frameset>
<noframes>
<body>
<p align="center">If you can read this 
message your browser does not support frames.</p>
</body>
</noframes>
</html>
			
This web page will require 8 different HTML files to display, one blueprint document with the HTML code above plus 7 more HTML documents that make up the content as defined by the <frame src...> tags. Carefully compare the diagram with the "nesting" of the multiple <frameset...> tags.

Yes, it gets complicated! And... You will learn even more things you can do with the HTML code for frames as you work through the examples below.

So for just an experiment I'm going to show you how to cut you site up into frames. You don't have to cut up the site you've been working on. You can DOWNLOAD a second copy to alter and practice on.

framed

The top frame will contain our heading to our web site along with the image of the widow maker.

The two bottom frames, the frame to the left will contain our navigation. And the right frame will contain all our sites content.

  1. Ok so let's make a new html file and name it framed.htm which will our starting file.
  2. The code for our frame set up will look like this:
    <html>
    <head><title>Eazy Space Tours Framed</title></head>
    <!-- This line below splits your page into two rows -->
    <frameset rows="160,*" border="0">
    <!-- This is the top frame -->
       <frame name="header" src="content/head.htm" 
       noresize="noresize" scrolling="no">
       <!-- This line splits second row into to columns-->
       <frameset cols="195,*" border="0">
       		<!-- This is the left column -->
           <frame name="menu" src="content/menu.htm" 
    	   noresize="noresize" scrolling="no">
    	   <!--This is the right column -->
    	   <frame name="content" src="content/intro.htm">
       </frameset>
    </frameset>
    <noframes>
    <body>If you can read this your browser does not
    support frames</body>
    </noframes>
    </html>
    			  
    			  
  3. Save and Re-Load project.
    Ok in the first frame set we have set the top frame row to be 160 pixels high, we set the name of that frame to <frame name="header" we also added the attributes noresize="noresize" so that the frame height can not be altered. Also the attribute scrolling="no", this stops the scroll bars appearing on the side and or bottom of the page and also told it a src="xxxx/xxxx.htm" to display with in the frame. Then the * (star) represents the rest of the web page which we have then split into 2 columns. These to columns are named with the <frame name="xxxxx"> attribute. You will notice that the frame that is named content does not have all the same attributes. This is because we need to be able to scroll though our content in that frame, we also don't need the noresize on this frame as it was already stated in the first frame.

    NOFRAMES, what's that??? This should be also written into the code as well. It simply displays a message for some one to read if there browser does not display frames.

    If done correctly you should have 3 sections all displaying an error message page in each frame saying that the page could not be displayed. That's because we don't have any pages for it to display, we now have to create them.

    This design allows us to break up the project page into more discrete chunks; for now they are small chunks, but perhaps you could see how this might be useful if we had much more content for each section. And that is what I'm showing you how to do here is an example of how it could be done, not how it has to be done.

    It also saves on download time as 2 of the frames stay the same and never change. So the only thing it changes is the content in 1 frame.

  4. Now let's make the rest of the files we need to make the framed page complete. We are going to slice apart our index page and make it into 2 pages. First let's make a page called head.htm and place in this line of code from our index.htm and change it slightly as showed here.
    head.htm
    
    <html>
      <head>
       <title>Eazy Space Tours</title>
      </head>
    <body bgcolor="#000000" text="#FFFFCC" 
       link="#33CCFF" vlink="#FF0000" alink="#FF0000" 
       topmargin="0">
    <img src="images/spaceship.jpg" 
    alt="Eazy Tours Luxury Liner the Widow Maker" 
    width="207" height="170" align="left" />
    <div align="right">
    <p>
     <b><font face="Arial,Helvetica" font size="+4" 
     color="#FF6600">E</font>
     <font face="Arial,Helvetica" size="+3" color="#CC6600">
     AZY SPACE TOURS</font></b>
    </p>
     <p> In this lesson you will use the Internet to research 
     information on Space Tours and then add things to our web 
    site.</p>
     <hr />
    <br clear="left" />
    </div>
    </body>
    </html>			
    			
    NOW THE menu.htm file	
    
    <html>
      <head>
       <title>Eazy Space Tours</title>
       </head>
    <body bgcolor="#000000" text="#FFFFCC" 
       link="#33CCFF" vlink="#FF0000" alink="#FF0000">
    <p>
    <b>In this Lesson...</b><br />
     <font size=+1><i>
       <a href="intro.htm" target="content">
         Introduction</a><br />
       <a href="venus.htm" target="content">
         Venus</a><br />
       <a href="volcanic.htm" target="content">
         Volcanic Tours Of Venus</a><br />
       <a href="tropical.htm" target="content">
         Tropical Centres Of Venus</a><br />
       <a href="uranus.htm" target="content">
         Uranus</a><br />
       <a href="mtwanna.htm" target="content">
         Skiing On Mt. WannaHockALoogie</a><br />
       <a href="lakeunix.htm" target="content">
         Skating on Lake Unix</a><br />
    </i></font>
    </p>		
    </body>
    </html>
    		
    			
  5. Now that we have made and altered the files we do not have to make any more files for our site. The content has already been made and is been targeted into the content frame. We must change just one thing though in the rest of our other pages. Where we had
    
      <a href="index.htm">index</a>		
    			
    	Change it to
    		
      <a href="intro.htm">index</a>	
    	

CHECK YOUR WORK
If all is well you compare your work to this EXAMPLE and hopefully yours will work the same way as this does. If it doesn't carefully check everything you've entered into you text editor for all the pages and make sure its right.

A FEW MORE FRAME OPTIONS

	<frameset border="N"
	<frameset frameborder="N"
	<frameset bordercolor="#xxxxxx"

Each attribute has a different function in the <frameset tag changing between netscape and internet explorer.

The BORDERCOLOR attribute changes and sets the border color of your frames.
The BORDER attribute sets the width of the border with a number, 0(zero) been off and 1 been on and the higher the number the wider the border.
The FRAMEBORDER varies between browsers and generally turns on the border between rows.

INDEPENDANT PRACTICE
Try making your own framed site for practice and try using the different attributes as well.



Top of page | Previous Lesson| Lessons Index | Next Lesson


Copyright © 2004 - EazyHTML.com