Webmaster
-
Frames
You were given the script for frames in the chapter Your first website. If you are happy to use that example for your website there is no need to learn about them. But if you want to change the format then delve here.
Firstly, remember that columns run down the screen, and rows run across the screen.
Here is what I did:
- I called my screen a frameset.
<frameset cols="160,620,*">
</frameset>
You can see the cols="" which split the frameset into 3 columns.
- I split my screen frameset into 3 columns, each also called a frameset.
<frameset cols="160,620,*">
<frameset rows=""> This has a width of 160px.
</frameset>
<frameset rows=""> This has a width of 620px.
</frameset>
<frameset rows=""> This has a width of *px, which means what is left over after 160px + 620px have been used up..
</frameset>
</frameset>
- Then I went down each column frameset, splitting it into frames, by giving values to the rows.
<frameset cols="160,620,*">
</frameset>
You can see the cols="" which split the frameset into 3 columns.
- I split my screen frameset into 3 columns, each also called a frameset.
<frameset cols="160,620,*">
<frameset rows="100,10,*"> This has a width of 160px.
</frameset>
<frameset rows=""> This has a width of 620px.
</frameset>
<frameset rows=""> This has a width of *px, which means what is left over after 160px + 620px have been used up..
</frameset>
</frameset>
I split my screen into columns, called framesets.
Open index_major.htm in Notepad.
Note there are no body tags, no <body></body>.
Instead we have frames as scripted here:
<frameset cols="160,621,*" frameborder="0" border="0" >
"border" for Netscape; "frameborder" for Internet Explorer; framespacing="n" increases space between frames but used by only Internet Explorer, so do not use.
f1 includes 2 frames: logo, index.
<frameset rows="85,*" frameborder="no" border="0" >
<frame name="logo" src="1_logo.htm" scrolling="no" marginheight="0" marginwidth="0" />
<frame name="index" src="2_index.htm" scrolling="auto" marginheight="0" marginwidth="0" />
</frameset>
f2 includes 1 frame for content: f2
<frameset frameborder="no" border="0" >
<frame name="f2" src="3_first_page.htm" scrolling="auto" marginheight="0" marginwidth="0" />
</frameset>
f3 includes 1 frame for advertising or photos: f3
<frameset frameborder="no" border="0" >
<frame name="f3" src="4_f3.htm" scrolling="auto" marginheight="0" marginwidth="0" />
</frameset>
</frameset>
This looks very complicated, but when we begin we create a simple framework then keep expanding, like this:
<frameset cols="160,621,*" frameborder="0" border="0" >
</frameset>
</html>
We have now created a set of 3 frames with the widths of 160px, 621px and the 3rd has whatever pixels are left over, because we do not know how wide the user will set his window.
Note that we said there is no frameborder and no border. Actually a frameborder is the same as a border, but one browser uses one term and another browser uses the other, so we cover both.
Now we include 3 frames within this frameset.
<frameset cols="160,621,*" frameborder="0" border="0" >
<frame name="f1" src="1_index.htm" scrolling="auto" marginheight="0" marginwidth="0" />
<frame name="f2" src="3_first_page.htm" scrolling="auto" marginheight="0" marginwidth="0" />
<frame name="f3" src="4_f3.htm" scrolling="auto" marginheight="0" marginwidth="0" />
</frameset>
</html>
This is what we have done:
- <frame ...>: within the frameset, we have made 3 frames
- name="f2": names each frame so we can reference them later. I use f1, f2, f3 for convenience of remembering.
- src="3_first_page.htm": calls a file to fill the frame.
- scrolling="auto": puts a scrollbar alongside the page for the user to scroll pages that are too long for the monitor.
- marginheight="0": separates the content from the top and bottom edges of the frames. I keep this as zero, then add the margin in the stylesheet [see chapter Stylesheets]. This avoids later confusion.
- marginwidth="0": separates the content from the left and right edges of the frames. I keep this as zero, then add the margin in the stylesheet.
You should add the script which precedes this, and test it.
We could let it go at that, but I prefer a small logo in the top-left corner, so the user always know at which site he is. When that disappears, he knows instantly he has left my site (and needs to click the [Back] button to return.
To do this I swap the left-most frame for another frameset into which I put 2 frames.
Just like before, we begin:
<frameset rows="85,*" frameborder="no" border="0" >
</frameset>
We do not know how long is the user's window or screen so we put "85,*" to fix the size of the logo but leave the other frame to take up the rest of the space.
Then we expand by adding the 2 frames inside the frameset:
<frame name="logo" src="1_logo.htm" scrolling="no" marginheight="0" marginwidth="0" />
<frame name="index" src="2_index.htm" scrolling="auto" marginheight="0" marginwidth="0" />
Again we call a page for each frame.
And that is all there is to it.
Knowing these techniques you can alter the number of frames. You might prefer your logo to be at the top of the middle frame, and you can now do that.
You might wish to fix the width of the 3rd frame at 150px because your advertisements are just under this size. This would enable you to vary the middle frame. You now know how to do that.
If you fix the widths of all frames, then if the monitor is too small, the user will need a horizontal scrollbar, and he will not like it.
But it is your website and you can do what you like.
You can use frames within your main window. These are called "iFrames" or Inline Frames, which insert an XHTML or HTML document within another document.
This is part of the HTML 4 specification. One advantage of iFrames is that they can have their own scrollbars. However, at this early stage of your webmastering, stick to the KISS principle – keep it simple. Furthermore, for users who want to copy your content, iFrames are a nuisance.
You might have wondered why my website splits into 4 vertical framesets, giving index-content-content-border, and here are some of the reasons:
- the index is customarily on the left
- the border on the right balances the color of the index on the left
- the left content-window is naturally placed next to its index, and is fixed in width by the need for users to cut-and-paste onto A4 pages without cutting off the right-edge of the text
- the remaining space, the 3rd frame providing a second content-window, is ideal for photos accompanying the main text, for extra text or for advertising (which I do not do), but its width as viewed by the user is determined by both the monitor and its dpi (dots-per-inch) setting. Most 'Westerners' will have monitors that give usefully wide second-windows, but most of my users, limited to old technology, may not have any second-window.
My website is designed for monitors 800px wide.
With this 4-frame layout, is there any need for iFrames ?