<layer> 
- Function:
-
Define a layer of content within a document
- Attributes:
-
ABOVE | NAME |
BACKGROUND | SRC |
BELOW | STYLE |
BGCOLOR | TOP |
CLASS | VISIBILITY |
CLIP | WIDTH |
LEFT | Z-INDEX |
- End tag:
-
</layer>; always used
- Contains:
-
body_content
- Used in:
-
block
|
Regardless of its origin, Netscape formats a layer's content
exactly like a conventional document, except that the result is
contained within that separate layer, apart from the rest of your
document. You control the position and visibility of this layer using
the attributes of the <layer> tag.
Layers may be nested, too. Nested layers move with the containing
layer and are visible only if the containing layer itself is visible.
14.3.1.3. The above, below, and z-index attributes
Layers exist in three
dimensions, occupying space on the page and stacked atop one another
as well as on top of conventional document content. As we mentioned
earlier, layers normally get stacked in order of their appearance in
the document: layers at the beginning get covered by later layers in
the same display area.
You can control the stacking order of the layers with the
above, below, and
z-index attributes for the
<layer> tag. These attributes are mutually
exclusive; use only one per layer.
The value for the above or
below attribute is the name of another layer in
the current document. Of course, that referenced layer must have a
name attribute whose value is the same name you
use with the above or below
attribute in the referring <layer> tag. You
also must have created the referenced layer earlier in the document;
you cannot refer to a layer that comes later.
In direct contradiction with what you might expect, Netscape puts the
current layer below the above named layer, and
above the below named layer.[72] Oh, well. Note the layers must occupy the
same display space for you to see any effects.
Let's use our drop shadow layer example again to illustrate the
above attribute:
<layer>
<layer name=text left=0 top=0>
<h1>Introduction to Kumquat Lore</h1>
</layer>
<layer name=shadow above=text left=2 top=2>
<h1><font color=gray>Introduction to Kumquat Lore</font></h1>
</layer>
</layer>
The above attribute in the layer named
shadow tells Netscape to position the shadow layer
so that the layer named text is above it. The
effect is identical to Figure 14-9.
The above and below attributes
can get confusing when you stack several layers. We find it somewhat
easier to use the z-index attribute for keeping
track of which layers go over which. With z-index,
you specify the order in which Netscape stacks the layers: higher
z-index value layers get put on top of lower
z-index value layers.
For example, to create our drop shadow using the
z-index attribute:
<layer>
<layer left=0 top=0 z-index=2>
<h1>Introduction to Kumquat Lore</h1>
</layer>
<layer left=2 top=2 z-index=1>
<h1><font color=gray>Introduction to Kumquat Lore</font></h1>
</layer>
</layer>
Again, the effect is identical to Figure 14-9.
Normally, Netscape would display the second layer -- the gray one
in this case -- on top of the first layer. But since we've
given the gray layer a lower z-index value, it is
placed behind the first layer.
The z-index values need not be sequential,
although they must be integers, so we could've used the values
99 and 2, respectively, and gotten the same result in the previous
example. And you need not specify a z-index for
all the layers that occupy the same display space -- only those
you want to raise or lower in relation to other layers. However, be
aware that the order of precedence may get confusing if you
don't z-index all related layers.
For instance, what order of precedence by color would you predict
when Netscape renders the following sequence of layers?
<layer left=0 top=0 z-index=3>
<h1><font color=red>Introduction to Kumquat Lore</font></h1>
</layer>
<layer left=4 top=4>
<h1><font color=green>Introduction to Kumquat Lore</font></h1>
</layer>
<layer left=8 top=8 z-index=2>
<h1><font color=blue>Introduction to Kumquat Lore</font></h1>
</layer>
Give yourself a star if you said that the green header goes on top of
the red header which goes on top of the blue header. Why? Because the
red header is of lower priority than the green header based on order
of appearance, and we forced the blue layer below the red one by
giving it a lower z-index value. Netscape displays
z-indexed layers according to their given order
and non-z-indexed layers according to their order
of appearance in the document. Precedence based on order of
appearance also applies for layers that have the same
z-index value. If you nest layers, all the layers
at the same nesting level get ordered according to their
z-index attributes. This group is then ordered as
a single layer among all the layers at the containing level. In
short, layers nested within a layer cannot be interleaved among
layers at a different level.
For example, consider these
nested
layers, with their content and end tags omitted for clarity
(indentation indicates nest level):
<layer name=a z-index=20>
<layer name=a1 z-index=5>
<layer name=a2 z-index=15>
<layer name=b z-index=30>
<layer name=b1 z-index=10>
<layer name=b2 z-index=25>
<layer name=b3 z-index=20>
<layer name=c z-index=10>
Layers a, b, and
c are at the same level, with layers
a1 and a2 nested with
a, and b1,
b2, and b3 nested within
b. Although the z-index numbers
might at first glance appear to cause Netscape to interleave the
various nested layers, the actual ordering of the layers, from bottom
to top, is c, a,
a1, a2, b,
b1, b3, and
b2.
If two layers are nested within the same layer and they have the same
z-index value, the layer defined later in the
document is placed on top of the previously defined layer.[73]
14.3.1.4. The background and bgcolor attributes
Like
the corresponding attributes for the <body>
tag, you may define the background color and an image for a Netscape
layer with the bgcolor and
background attributes, respectively.[74] By default, the background of a layer is transparent,
allowing lower layers to show through.
The bgcolor attribute accepts a color name or RGB
triplet as its value, as defined in Appendix G, "Color Names and Values". If
specified, Netscape sets the entire background of the layer to this
color, rendering the layer opaque. This attribute is handy for
creating a colored box behind text, as a highlighting or
attention-getting mechanism. It will, however, hide any layers below
it, including conventional HTML content.
The background attribute accepts the URL of an
image as its value. The image is tiled to fill the area occupied by
the layer. If portions of the image are transparent, those portions
of the layer will be transparent, and underlying layers will show
through.
If you include both attributes, the background color will show
through the transparent spots in the background image. The whole
layer will be opaque.
The background attribute is useful for placing a
texture behind text, but it fails miserably when the goal is to
render text in front of a fixed image. Since the size of a layer is
dictated by its contents, not the background image, using the image
as the background will cause it to be clipped or tiled, depending on
the size of the text. To place text reliably atop an image, use one
layer nested within another:
<layer>
<img src="sunset.gif">
<p>
<layer top=75>
<h2 align=center>And they lived happily ever after...</h2>
</layer>
</layer>
Netscape sets aside space for the entire image in the outer layer.
The inner layer occupies the same space, except that we shift it down
75 pixels to align the text better over the image. The result is
shown in Figure 14-11.
Figure 14-11. Placing text over an image using layers