Working with Layers


Now that you have a formal understanding of the power layers expose, let's actually insert and work with them in Dreamweaver. In the following sections, you'll learn about the various techniques for inserting layers, modifying layer properties through the Properties Inspector and the Layers panel, building a table-less web page, and using behaviors to facilitate interaction between the user and layers in the page.

To begin working with the examples in this chapter, you'll need to download the support files online. As you have done for the rest of the chapters in this book, you can work with the examples in this chapter by downloading the files from www.dreamweaverunleashed.com. You'll want to save the files for Chapter 11 in an easy-to-find location. I'll place mine in C:\Dorknozzle\Chapter11.

Inserting a Layer

You have a couple options for inserting layers into a web page; the method you use depends on your needs and skill set. By far the easiest method for inserting a layer is to use the Layer option in the Insert, Layout Objects submenu. To use this method, follow these steps:

1.

Create a new HTML page by choosing the New option from the File menu. When the New Document dialog appears, select the HTML option from the Basic Page category and click Create.

2.

Place your cursor on the page and select Insert, Layout Objects, Layer. The new layer appears on the page similar to Figure 11.3.

Figure 11.3. A new layer is added to the page using the Insert menu.


Initially, you'll notice that the layer simply appears as a box with a 1-pixel border surrounding it. You can easily select the layer by rolling your cursor over the border of the layer until your cursor turns into the Move icon. Now simply click to select the layet. Notice that the layer highlights blue and displays small blue squares, otherwise known as resize handles, at each point and in the middle of each line. Also notice that a handle appears in the top-left corner of the layer, also shown in Figure 11.3.

You can use the small black resize handles to click, hold, and drag out to resize the layer vertically, horizontally, or both. Furthermore, you can use the top-left handle to select and move the layer anywhere you want on the page.

TIP

Dreamweaver also allows you to select a layer by its border and move it around on the page. If you use this method, make sure that you don't accidentally select a resize handle, or you'll find yourself resizing the layer as opposed to moving it.


Drawing a Layer

Another simple alternative to adding a layer to the page is to use the Draw Layer method. With this method, you can easily click and draw a layer in the page to any dimensions that you want. To use this method, follow these steps:

1.

Switch to the Layout category in the Insert bar.

2.

Select the Draw Layer icon, third from the left in the Layout category in the Insert bar.

3.

Place your cursor on the page, click, hold, and drag out to draw the layer in the Document window.

The layer is eventually created to look similar to the one created with the first method. The only difference is that by drawing a layer, you can set the initial dimensions to anything you want as opposed to setting them at the default 200 pixels by 115 pixels. We'll use this method, in conjunction with the Grid (explained later in the chapter) to draw layers when we build the table-less version of the Dorknozzle site.

Inserting Content into Layers

Inserting content into a layer is just as easy as it is to insert content into the cell of a table. To demonstrate this, I'll insert text into the first layer (the one at the top-left of the page) and insert an image into the second layer (the one on the center of the page). To insert text into the first layer, simply place your cursor into the layer and start typing the text Ada the Admin Assistant. Now let's insert Ada's headshot photograph into the second layer. To do this, drag the head_adatheadminassistant.gif image (located in the Images folder of our defined site in the Files panel) into the layer. When you've finished, the page will resemble Figure 11.4.

Figure 11.4. Add text to the first layer and drag an image into the second layer.


Notice that the text and the image are slightly undersized compared to the size of the layers. To resize the layers to correspond with their content, simply click, hold, and drag the resize handle located in the bottom-right of each layer to resize the layer respective to the size of the content within it. Finally, move the layer that contains the headshot photograph and place it just underneath the text layer. The result looks like Figure 11.5.

Figure 11.5. Resize the layer so that it matches the size of the content within it and drag the headshot layer so that it sits just underneath the text layer.


You'll begin to notice the flexibility that layers expose: Adding them to the page is easy, moving them is easy, and resizing them respective to the content within them is easy. In the next few sections, we'll discuss the various properties you can set using the Properties Inspector and the Layers panel.

Modifying Layer Properties with the Properties Inspector

Like every feature in Dreamweaver, layers expose properties you can customize using the Properties Inspector. If you haven't noticed, the layers-based Properties Inspector becomes available when you select a layer. As you can see in Figure 11.6, the Properties Inspector exposes properties that uniquely identify the layer, that set the dimensions of the layer, set the stacking order or z-index of the layer, and so on. Also notice that moving your cursor just over the layer displays properties already set for the layer within a yellow ToolTip.

Figure 11.6. The layers-based Properties Inspector exposes numerous customizable properties. Moving your cursor over the layer exposes the properties already set for the layer within a ToolTip.


A complete list of customizable properties exposed by the layers-based Properties Inspector is given here:

  • Layer ID: Add a value in this text box to uniquely identify the selected layer. By default, Dreamweaver adds the value Layer1, Layer2, and so on as you add layers to the page. Of course, the default names mean little to us, so we'll change them. To demonstrate this, select each of the two layers and name them AdaImage and AdaText respectively. Also note that you can use only standard alphanumeric characters when naming a layer. Spaces, hyphens, slashes, and periods are not allowed.

  • L and T: Enter values into these text boxes to set the position of the layer from the Top and Left side of the browser. The Left and Top values are measured from the top-left point of the layer. If you're working with nested layers, the Left and Top values are measured from top and leftmost corner of the parent layer.

  • W and H: Enter values in these text boxes to set the width and height of the layer. If the content in the layer exceeds the width or height of the layer, Dreamweaver automatically stretches the layer to accommodate the content within it. As you'll see, you can change the Overflow property to set how the browser handles the excess content in the browser.

  • Z-Index: Enter a value in this text box to set the stacking order of the layer. The lower the number, the lower the layer appears in the stacking order. The higher the number, the higher the layer appears in the stacking order. To demonstrate this property, select the AdaImage layer and change the Z-Index to 2. Now select the AdaText layer and change that Z-Index to 1. Position the AdaImage layer over the AdaText layer. As you can see from Figure 11.7, the AdaImage layer partially hides the AdaText layer. Of course, you know this is possible because the AdaImage layer has a higher Z-Index (2) than the AdaText layer (with a Z-Index value of 1).

    Figure 11.7. Layers with higher Z-Indexes appear above layers with lower Z-Indexes.


  • Vis: Select from the four options in this menu to set the visibility of the layer. Options include Default (which is essentially the same as Inherit), Visible (which makes the layer visible), Hidden (which hides the layer and the content within it), and Inherit (which assumes the visibility property of the parent layer when the layer is nested). If a layer is not nested within another layer, the default of Visible kicks in. When a layer is hidden, you'll want to use a scripting language such as JavaScript (the Show/Hide Layer behavior in Dreamweaver's case) to dynamically set the visibility property of the layer.

  • Bg image: Use the Browse to Folder icon to find and select an image to use as the layer's background. Background images in layers are treated the same as the page and tables in that images smaller than the size of the layer end up tiling. Of course, you can always use the Repeat property in CSS to set how the background image for a layer tiles or repeats.

  • Bg color: Choose a color from this color picker to set the background color of the layer. Leave this option blank to make the layer transparent.

  • Class: When working with CSS, pick a class from this menu to change the style of the layer according to the rule set out within the selected class.

  • Overflow: Select an option from this menu to set how the browser should treat a layer when the content exceeds the width or height of the layer. Options include Visible, Hidden, Scroll, and Auto. Choosing Visible forces the browser to stretch the layer to accommodate the content in the layer. Choosing Hidden forces the browser to automatically crop the excess content when it exceeds the width or height of the layer. Choosing Scroll forces the browser to automatically add a scrollbar at the right and bottom of the layer. These scrollbars appear even if the content in the layer doesn't exceed the width or height of the layer. Choosing Auto forces the browser to automatically add a scrollbar at the right of the layer only if the content exceeds the height of the layer and to add a scrollbar to the bottom of the layer only if the content exceeds the width of the layer.

  • Clip: Enter values in these text boxes to define the visible area of the layer. You can specify values for the Left, Top, Right, and Bottom coordinates to "clip" off content within the layer.

As you'll see throughout the chapter, a layer is nothing more than a <div> or <span> tag complete with a unique ID and a document-wide style rule (by default). Modifying properties in the Properties Inspector simply changes the document-wide style rule accordingly. To demonstrate this, switch to Code view. As you can see from Figure 11.8, each layer is nothing more than a <div> tag with an ID and a document-wide style rule.

Figure 11.8. Layers are nothing more than a <div> or <span> tag complete with a unique ID and an inline style rule.


You're probably thinking that inline styles aren't the best way of manipulating properties for layers. If that's what you're thinking, you're right! Assuming that you were developing your site entirely in layers, changing all the layer's properties in your site would be a nightmare if all the styles were developed inline. A much better alternative is to create an ID within a style sheet that defines layer properties similar to the styles you'd use in the document-wide method. When you want to make global properties adjustments (such as positioning properties), you make them once in the style sheet and you're done. We'll demonstrate this process later in the chapter.

Modifying Layer Properties with the Layers Panel

Another option for customizing layer properties is the Layers panel. You can use the Layers panel as a way to set a layer's ID, Visibility properties, Z-Index, and whether or not layers can overlap each other. The Layers panel, shown in Figure 11.9, can be selected directly from the CSS Styles panel group or by choosing the Layers option from the Window menu or by pressing F2. Alternatively, you can right-click a layer's border to access the context menu and choose the Layers Panel option to open the Layers panel.

Figure 11.9. Use the Layers panel to visually set visibility, Z-Index, layer ID, and overlapping properties.


With the Layers panel open, notice that the style and overall appearance is strikingly familiar, looking much like a Layers panel would in an image-editing program such as Fireworks. For instance, you can drag layers above or below other layers, effectively changing the Z-Index of the layers on the page.

TIP

If you drag a layer in the Document window that doesn't contain a Z-Index, Dreamweaver automatically adds one for you.


You can also click in the eyeball column to change the initial Visibility property for a layer. Finally, you can double-click in the Name column to change the Layer ID of the selected layer. All this and more is possible through the Layers panel. The following features are exposed from the Layers panel:

  • Visibility: You can click in this column for a particular layer to change the Visibility property for a layer. Icons include a closed eye (which represents Hidden), an open eye (which represents Visible), and no eye, the default (which represents Inherit).

  • Name: You can double-click the layer name in this column to change the layer ID for the specific layer.

  • Z: You can double-click the layer in this column to change the Z-Index (stacking order) for the specific layer. Of course, you can also drag and drop layers above or below other layers in the Layers panel to accomplish the same task.

  • Prevent overlaps: When designing layer-based sites, click this button to prevent layers from overlapping each other. This is important when you want to work with two layers next to each other but want to prevent them from falling into an area used by another layer. We'll discuss this option further in the next section.

It's important to understand the place of the Layers panel. Sure, most of these properties can be set by simply selecting the layer and making the necessary change in the Properties Inspector. The difference between the Properties Inspector and the Layers panel however, is that the Layers panel allows you to work with layers even when they're hidden from view. Because the Properties Inspector becomes available only when a layer is selected, there is no way of changing the Visibility of a layer back to Visible once it's been Hidden if it weren't for the Layers panel. Also, it's important to note that the Layers panel represents the collection of layers on the page as opposed to a single layer, which is what the Properties Inspector is for. The Prevent Overlaps check box prevents all layers on the page from overlapping each other, as discussed in the next section.

Preventing Layers from Overlapping

As mentioned in the previous section, you can use the Prevent Overlaps check box in the Layers panel to prevent all layers on your page from accidentally overlapping each other when you position them. To demonstrate this feature, follow these steps:

1.

Click the Prevent Overlaps check box in the Layers panel.

2.

Try to drag the AdaImage layer above the AdaText layer as you did earlier in the chapter. You'll quickly notice that Dreamweaver prevents you from doing that.

3.

To disable the feature, simply disable the Prevent Overlaps check box.

As mentioned earlier, this feature comes in handy when designing layer-based websites because it can prevent you from accidentally moving a layer above or below another layer.

Nesting Layers

Similar to the process of nesting tables within a cell of another table, layer nesting is the process of placing content in one layer within another layer. By default, Dreamweaver doesn't automatically nest layers; instead, Dreamweaver allows you to enable this option in the Layers category of the Preferences window. To enable layer nesting in your site, follow these steps:

1.

Select the Preferences option from the Edit menu (or press Ctrl+U in Windows or Option+U on a Mac). The Preferences window appears.

2.

Select the Layers category.

3.

Enable the Nesting: Nest When Created Within a Layer check box.

4.

Click OK.

With that preference set, you can now create layers within other layers. For the most part, the process of nesting a layer within a second layer is as simple as drawing or inserting a layer within another layer. To do this, follow these steps:

1.

Insert or draw a new layer on the page and name it BgLayer.

2.

Select the layer and set the background color to gray by selecting a gray tone from the Bg Color field in the Properties Inspector.

3.

Create a nested layer by inserting a new layer within the existing BgLayer layer. Name the new layer NestedLayer.

4.

Insert a headshot image into the new NestedLayer layer so the result resembles Figure 11.10.

Figure 11.10. Nest a layer within an existing layer.


It won't be overly obvious that the new layer is nested within the BgLayer layer. However, you can see that the layer is in fact nested by looking at the Layers panel, also shown in Figure 11.10. As you can see, the NestedLayer layer appears as a child node beneath its parent BgLayer layer. The real benefit to nesting layers becomes evident when working with Visibility properties. Because the default Visibility property of a layer is Inherit, the child layer always inherits the properties of its parent layer. What this means is that all we have to modify is the parent BgLayer layer. Visibility changes made to this layer propagate down to all child layers, effectively saving us from doubling our efforts.

Although it may seem obvious that dragging a nested layer out of its container layer would un-nest a layer, this is in fact not true. To un-nest a layer, you must use the Layers panel to drag a child layer out of its current position and reposition it higher in the Layers panel list.

Deleting a Layer

If you decide that a particular layer is no longer needed, you can easily delete it using one of three methods. The easiest way to delete a layer is to select it on the page and press the Delete or Backspace key on your keyboard. This action effectively removes the layer and its content from the document. Alternatively, select a layer from the Layers panel and press the Delete or Backspace key. Either method produces the same result. The third option for deleting a layer from the Document window is to right-click the <div> tag in the Tag Selector and choose the Remove Tag option from the context menu.




Macromedia Dreamweaver 8 Unleashed
Macromedia Dreamweaver 8 Unleashed
ISBN: 0672327600
EAN: 2147483647
Year: 2005
Pages: 237
Authors: Zak Ruvalcaba

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net