A layer is an absolutely positioned division, namely, a div block in which the position style property is absolute. See the section about absolute positioning in Notes 9 for a discussion and some examples. When the position style property is set to absolute, the top and left style properties are used to set the division's location. When layers are allowed to overlap, the z-index style property can be used to determine the layering order.
The term layer derives from the (long deprecated) HTML element of this name used originally in Netscape Navigator 4. The layer element has been superceded by the absolutely positioned division.
In a layer-based layout, normally everything is put into a layout and these layers do not overlap.
In order to create a layered version of our sample website used in Experiment 6, we could leave the logo image alone and place the left navigation and right content sections in layers. Bearing this in mind the global style file, mystyle.css would be used to specify the divisions nav and content:
body {
background-color: palegoldenrod;
}
div.hdr {
position: absolute;
top: 10px;
left: 25px;
}
div.nav {
position: absolute;
top: 150px;
left: 15px;
width: 150px;
padding: 10px;
line-height: 4ex;
background-color:lavender;
border: solid 1px red;
}
div.content {
position: absolute;
top: 150px;
left: 200px;
}
All the documents which use this layout would observe
the following template:
<html> <head> <title></title> <style> @import url(mystyle.css); </style> </head> <body> <div class="hdr"> <img src="../images/header.gif" alt="My Website" height="120" width="500"/> </div> <div class="nav"> Links </div> <div class="content"> Page content </div> </body> </html>The structure of the document webdesign.html is this:
<html>
<head>
<title></title>
<style>
@import url(mystyle.css);
h2.top { margin-top: 0px; } /* fix for first header */
</style>
</head>
<body>
<div class="hdr">
<img src="../images/header.gif" alt="My Website" height="120" width="500"/>
</div>
<div class="nav">
Links
</div>
<div class="content">
<h2 class="top">What I've Learned in Web Design</h2>
<table summary="" cellpadding="5px" width="100%">
<tr valign="top">
<td width="30%">
<h3>HTML</h3>
...
</td>
<td width="1%"></td>
<td width="30%">
<h3>Lists</h3>
...
</td>
<td width="1%"></td>
<td width="30%">
<h3>Graphical Images</h3>
...
</td>
</tr>
</table>
</div>
</body>
</html>
We still want to use a table, but the table structure is
now completely inside the content div.
To see the overall effect,
<html>
<head>
<title>Frames(1)</title>
</head>
<frameset rows="140,*">
<frame name="top" src="header.html" />
<frameset cols="150,*" >
<frame name="left" src="nav.html" />
<frame name="right" src="home.html" />
</frameset>
<noframes>
You are obliged to create a separate-but-equal website here
without using frames!
</noframes>
</frameset>
</html>
The left and right portions are themselves contained in
a frameset.
The files consist of
body { background-color: palegoldenrod; }
<html> <head> <title></title> <style> @import url(mystyle.css); </style> </head> <body> <img src="../images/header.gif" alt="My Website" height="120" width="500"/> </body> </html>
<html> <head> <title></title> <style> @import url(mystyle.css); </style> </head> <body> </body> </html>
<html>
<head>
<title></title>
<style>
@import url(mystyle.css);
body { margin: 0px; }
div.main {
line-height: 4ex;
padding: 10px;
line-height: 4ex;
background-color:lavender;
border: solid 1px red;
}
</style>
</head>
<body>
<div class="main">
<a target="right" href="home.html">Home</a><br />
<a target="right" href="webdesign.html">Web Design</a><br />
<a target="right" href="moves.html">Favorite Movies</a><br />
<a target="right" href="hobbies.html">My Hobbies</a><br/>
<a target="right" href="songs.html">Top 10 Songs</a><br/>
</div>
</body>
</html>
Note that these hyperlinks use the additional target attribute.
In the usage:
target="right"the value "right" corresponds to the frame with name="right" and is used to cause the hyperlink page to be displayed in the right frame instead of, by default, in the left frame where the navigation page is located.
<html>
<head>
<title>Frames(2)</title>
</head>
<frameset rows="140,*" frameborder="no" framespacing="0" border="0" >
<frame name="top" src="header.html" scrolling="no" />
<frameset cols="150,*" >
<frame name="left" src="nav.html" scrolling="no" />
<frame name="right" src="home.html" scrolling="no" />
</frameset>
<noframes>
You are obliged to create a separate-but-equal website
without using frames!
</noframes>
</frameset>
</html>
To see the overall effect of this modified version,
Although external
frames, once you've used them, appear quite elegant and efficient,
there are a number
of issues regarding their usage.
Here is a section quoted from the tutorial mentioned above:
At issue is the fact that you need to create a parallel website without frames and direct the user to it via the section:
- Frames Block Out Many People Whose Browsers Are Frames-Incapable
- When designing a framed site, it's important to remember that many people use browsers that can't handle frames. Contrary to some people's perceptions, this is not just because the user is too lazy to "get a real browser". Some people use text or audio browsers which render material in a linear fashion. Others simply dislike frames and turn them off in their browser's settings. If you don't include no-frames content, you are simply leaving out a portion of your potential audience.
- Frames Are Often Misused
- Probably the biggest problem with frames is that it is so easy to use them incorrectly. The web is filled with pages that use frames not because they are correct for the situation but because "they're cool". This is what gives frames a bad name. If you are considering using frames, make the choice based on what works best for your site, not on the mere availablility of "special effects".
- The Functionality of Frames Can Already Be Achieved Through More Standard HTML
- Most things that can be done with frames can be done without them... and in fact should be done without them anyway because you should always have a no-frames alternative. In fact, this is the reason many designers have abandoned frames: redundant effort. When I queried one large web site as to why they stopped having frames and no-frames versions the web master replied that it was too much work keeping them synchronized.
<noframes> ... </noframes>
<html>
<head>
<title>IFrames(1)</title>
<style>
@import url(mystyle.css);
div.nav {
padding: 10px;
line-height: 4ex;
background-color:lavender;
border: solid 1px red;
}
</style>
</head>
<body>
<img src="../images/header.gif" alt="My Website" height="120" width="500"/>
<table width="100%">
<tr valign="top">
<td width="150px">
<div class="nav">
<a target="content" href="home.html">Home</a><br />
<a target="content" href="webdesign.html">Web Design</a><br />
<a target="content" href="moves.html">Favorite Movies</a><br />
<a target="content" href="hobbies.html">My Hobbies</a><br/>
<a target="content" href="songs.html">Top 10 Songs</a><br/>
</div>
</td>
<td>
<iframe name="content" src="home.html"></iframe>
</td>
</tr>
</table>
</body>
</html>
Note that, as in external frames,
these hyperlinks use the additional target attribute.
In the usage:
target="content"the value "content" corresponds to the iframe with name="content" and is used to cause the hyperlink page to be displayed in the iframe instead of, by default, in the main page. We go back to using a table-layout (or layer-based layout if desired) except that the content section is an iframe dislaying the intial source for the home page, home.html. The files home.html and webdesign.html are exactly the same as the ones used for external frames. To see the overall effect, Obviously, we need to work with the attributes to get a better presentation. There are a number of attributes of iframes that you can use to control the display. Unfortunately, it does not work to set the height to 100% to avoid a vertical scrolling effect. Without other JavaScript techniques, you just have to set the height "big enough". The modified version of index.html differs only by this version of the iframe element:
<iframe name="content" src="home.html" width="100%"
frameborder="0" height="800"></iframe>
To see the overall effect of this modified version,
Note again that the links column is not crushed by the content.
We only needed to set a width on the td cell,
not the div element
within.