- Introduction to AP Elements
- Working with AP Elements
- Designing Tableless Web Pages Using AP Elements
- Built-In CSS Page Layouts
- Summary
Working with AP Elements
Now that you have a formal understanding of the power AP Elements are meant to provide, let's actually insert and work with them in Dreamweaver. In the following sections, you'll learn about the various techniques for inserting AP Elements, modifying AP Element properties through the Property inspector and the AP Elements panel, building a tableless web page using AP Elements and CSS positioning properties, and how to use built-in CSS page layouts.
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 7 in an easy-to-find location. I'll place mine in C:\VectaCorp\Chapter7. Also, don't forget to update your site reference in Dreamweaver to point to the newly created folder.
Inserting an AP Element
You have a couple options for inserting AP Elements into a web page; the method you use depends on your needs and skill set. By far the easiest method for inserting an AP Element is to use the AP Element option in the Insert, Layout Objects submenu. To use this method, follow these steps:
- Create a new HTML page by choosing File, New. When the New Document dialog appears, select the HTML option from the Basic Page category, choose the <none> option from the Layout list, and click Create.
- Place your cursor on the page and select Insert, Layout Objects, AP Div. The new 200 pixel by 115 pixel AP Element appears on the page similar to Figure 7.3.
Figure 7.3 A new AP Element is added to the page using the Insert menu.
Initially, you'll notice that the AP Element appears as a box with a border surrounding it. You can easily select the AP Element by rolling your cursor over the border of the AP Element until your cursor turns into the Move icon. Now click to select the AP Element. Notice that the AP Element 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 AP Element, also shown in Figure 7.3.
You can use the small resize handles to click, hold, and drag out to resize the AP Element vertically, horizontally, or both. Furthermore, you can use the top-left handle to select and move the AP Element anywhere you want on the page.
Drawing an AP Element
Another simple alternative for adding an AP Element to the page is to use the Draw AP Element method. With this method, you can easily click and draw an AP Element in the page to any dimensions that you want. To use this method, follow these steps:
- Switch to the Layout category of the Insert bar.
- Select the Draw AP Div icon, the second icon to the right of the Standard and Expanded buttons in the Insert bar.
- Place your cursor on the page, click, hold, and drag out to draw the AP Element in the Document window.
The AP Element is eventually created to look similar to the one created with the first method. The only difference is that by drawing an AP Element, you can set the initial dimensions to anything you want instead of 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 AP Elements when we build the tableless version of the Vecta Corp site.
Inserting Content into AP Elements
Inserting content into an AP Element 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 AP Element (the one at the top-left of the page) and insert an image into the second AP Element (the one on the center of the page that we just drew). To insert text into the first AP Element, place your cursor into the AP Element and start typing the text Ada the Admin Assistant. Now let's insert Ada's headshot photograph into the second AP Element. To do this, drag the head_adatheadminassistant.gif image (located in the Images folder of our defined site in the Files panel) into the AP Element. When you've finished, the page will resemble Figure 7.4.
Figure 7.4 Add text to the first AP Element and drag an image into the second AP Element.
Notice that the text and the image are slightly undersized compared to the size of the AP Elements. To resize the AP Elements to correspond with their content, click, hold, and drag the resize handle located in the bottom-right of each AP Element to resize the AP Element to the size of the content within it. Finally, move the AP Element that contains the headshot photograph and place it just underneath the text AP Element. The result looks like Figure 7.5.
Figure 7.5 Resize the AP Elements so they match the size of the content within them and drag the headshot AP Element so that it sits just above the text AP Element.
You'll begin to notice the flexibility that AP Elements reveal: 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 Property inspector and the AP Elements panel.
Modifying AP Element Properties with the Property Inspector
Like every feature in Dreamweaver, AP Elements have properties you can customize using the Property inspector. If you haven't noticed, the AP Elements Property inspector becomes available when you select an AP Element. As you can see in Figure 7.6, the Property inspector outlines properties that uniquely identify the AP Element, set the dimensions of the AP Element, set the stacking order or z-index of the AP Element, and so on. Also notice that moving your cursor just over the AP Element displays properties already set for the AP Element within a yellow ToolTip.
Figure 7.6 The AP Element-based Property inspector outlines numerous customizable properties.
A complete list of customizable properties outlined includes the following:
- Element ID—Add a value in this text box to uniquely identify the selected AP Element. By default, Dreamweaver adds the value apDiv1, apDiv2, and so on as you add AP Elements to the page. However, the default names mean little to us, so we'll change them. To demonstrate this, select each of the two AP Elements and name them AdaImage and AdaText, respectively. Also note that you can use only standard alphanumeric characters when naming an AP Element. Spaces, hyphens, slashes, and periods are not allowed.
- L and T—Enter values into these text boxes to set the position of the AP Element from the Left and Top of the browser. The Left and Top values are measured from the top-left point of the AP Element. If you're working with nested AP Elements, the Left and Top values are measured from top and leftmost corner of the parent AP Element.
- W and H—Enter values into these text boxes to set the width and height of the AP Element. If the content in the AP Element exceeds the width or height of the AP Element, Dreamweaver automatically stretches the AP Element 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 into this text box to set the stacking order of the AP Element. The lower the number, the lower the AP Element appears in the stacking order. The higher the number, the higher the AP Element appears in the stacking order. To demonstrate this property, select the AdaImage AP Element and change the Z-Index to 2. Now select the AdaText AP Element and change that Z-Index to 1. Position the AdaImage AP Element over the AdaText AP Element. As you can see from Figure 7.7, the AdaImage AP Element partially hides the AdaText AP Element. You know this is possible because the AdaImage AP Element has a higher Z-Index (2) than the AdaText AP Element (with a Z-Index value of 1).
Figure 7.7 AP Elements with higher Z-Indexes appear above AP Elements with lower Z-Indexes.
- Vis—Select from the four options in this menu to set the visibility of the AP Element. Options include Default (which is essentially the same as Inherit), Visible (which makes the AP Element visible), Hidden (which hides the AP Element and the content within it), and Inherit (which assumes the visibility property of the parent AP Element when the AP Element is nested). If an AP Element is not nested within another AP Element, the default of Visible kicks in. When an AP Element is hidden, you'll want to use a scripting language such as JavaScript (the Show/Hide AP Element behavior in Dreamweaver's case) to dynamically set the visibility property of the AP Element.
- Bg image—Use the Browse to Folder icon to find and select an image to use as the AP Element's background. Background images in AP Elements are treated the same as the page and tables, in that images smaller than the size of the AP Element end up tiling. However, you can always use the Repeat property in CSS to set how the background image for an AP Element tiles or repeats.
- Bg color—Choose a color from this color picker to set the background color of the AP Element. Leave this option blank to make the AP Element transparent.
- Class—When defining custom class selectors in CSS, pick a class from this menu to change the style of the AP Element according to the properties set out within the class rule.
- Overflow—Select an option from this menu to set how the browser should treat an AP Element when the content exceeds the width or height of the AP Element. Options include Visible, Hidden, Scroll, and Auto. Choosing Visible forces the browser to stretch the AP Element to accommodate the content in the AP Element. Choosing Hidden forces the browser to automatically crop the excess content when it exceeds the width or height of the AP Element. Choosing Scroll forces the browser to automatically add a scrollbar at the right and bottom of the AP Element. These scrollbars appear even if the content in the AP Element doesn't exceed the width or height of the AP Element. Choosing Auto forces the browser to automatically add a scrollbar at the right of the AP Element only if the content exceeds the height of the AP Element and to add a scrollbar to the bottom of the AP Element only if the content exceeds the width of the AP Element.
- Clip—Enter values into these text boxes to define the visible area of the AP Element. You can specify values for the Left, Top, Right, and Bottom coordinates to "clip" off content within the AP Element in the same way you'd crop an image in Fireworks or Photoshop.
As you'll see throughout the chapter, an AP Element 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 Property inspector changes the document-wide style rule accordingly. To demonstrate this, switch to Code view. As you can see from Figure 7.8, each AP Element is nothing more than a <div> tag with an ID and a document-wide style rule.
Figure 7.8 AP Elements are nothing more than a or tag complete with a unique ID and an inline style rule.
You're probably thinking that document-wide styles aren't the best way of manipulating properties for AP Elements. If that's what you're thinking, you're right! Assuming that you were developing your site entirely in AP Elements, changing all the AP Element's properties in your site would be a nightmare if all the styles were developed within individual pages. A much better alternative is to create an ID within a style sheet that defines AP Element properties globally. When you want to make property adjustments (such as positioning properties), you make them once in the style sheet and instantly those changes are propagated to all of the pages that make use of the style properties. We'll demonstrate this process later in the chapter.
Modifying AP Element Properties with the AP Elements Panel
Another option for customizing AP Element properties is the AP Elements panel. You can use the AP Elements panel as a way to set an AP Element's ID, Visibility properties, Z-Index, and whether AP Elements can overlap one another. The AP Elements panel, shown in Figure 7.9, can be selected directly from the CSS Styles panel group or by choosing the AP Elements option from the Window menu or by pressing F2. Alternatively, you can right-click (Control+click) an AP Element's border to access the context menu and choose the AP Elements Panel option to open the AP Elements panel.
Figure 7.9 Use the AP Elements panel to visually set visibility, Z-Index, ID, and overlapping properties.
With the AP Elements panel open, notice that the style and overall appearance is strikingly familiar, looking much like the Layers panel does in an image-editing program such as Fireworks or Photoshop. For instance, you can drag AP Elements above or below other AP Elements, effectively changing the Z-Index of the AP Elements on the page.
You can also click in the eyeball column to change the initial Visibility property for an AP Element. Finally, you can double-click in the Name column to change the ID of the selected AP Element. All this and more is possible through the AP Elements panel. The following customizable properties are revealed within the AP Elements panel:
- Visibility—You can click in this column for a particular AP Element to change the Visibility property. 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 AP Element name in this column to change the ID for the specific AP Element.
- Z-Index—You can double-click the AP Element in this column to change the Z-Index (stacking order) for the specific AP Element. You can also drag and drop AP Elements above or below one another to accomplish the same task.
- Prevent overlaps—When designing AP Element-based sites, click this button to prevent AP Elements from overlapping each other. This is important when you want to work with two AP Elements next to each other but want to prevent them from falling into an area used by another AP Element. We'll discuss this option further in the next section.
It's important to understand the place of the AP Elements panel. Sure, most of these properties can be set by selecting the AP Element and making the necessary change in the Property inspector. The difference between the Property inspector and the AP Elements panel, however, is that the AP Elements panel allows you to work with AP Elements even when they're hidden from view. Because the Property inspector becomes available only when an AP Element is selected, there is no way of changing the Visibility of an AP Element back to Visible after it's been Hidden without the use of the AP Elements panel. Also, it's important to note that the AP Elements panel represents the collection of AP Elements on the page, in contrast to the single AP Element that is covered by the Property inspector. The Prevent Overlaps check box prevents all AP Elements on the page from overlapping each other (discussed in the next section).
Preventing AP Elements from Overlapping
As mentioned in the previous section, you can use the Prevent Overlaps check box in the AP Elements panel to prevent all AP Elements on your page from accidentally overlapping each other when you position them. To demonstrate this feature, follow these steps:
- Click the Prevent Overlaps check box in the AP Elements panel.
- Try to drag the AdaImage AP Element above the AdaText AP Element as you did earlier in the chapter. You'll quickly notice that Dreamweaver prevents you from doing that.
- To disable the feature, uncheck the Prevent Overlaps check box.
Remember, this feature comes in handy when designing AP Element-based websites because it can prevent you from accidentally moving an AP Element above or below another AP Element.
Nesting AP Elements
Similar to the process of nesting tables within a cell of another table, AP Element nesting is the process of placing an AP Element within another AP Element. By default, Dreamweaver doesn't automatically nest AP Elements; instead, Dreamweaver allows you to enable this option in the AP Elements category of the Preferences window. To enable AP Element nesting in your site, follow these steps:
- Select Edit, Preferences (Dreamweaver, Preferences), or press Ctrl+U (Command+U). The Preferences dialog appears.
- Select the AP Elements category.
- Enable the Nesting: Nest When Created Within an AP Div check box.
- Click OK.
With that preference set, you can now create AP Elements within other AP Elements. For the most part, the process of nesting an AP Element within a second AP Element is as simple as drawing or inserting an AP Element within another AP Element. To do this, follow these steps:
- Insert or draw a new AP Element on the page and name it BgAPElement.
- Select the AP Element and set the background color to gray by selecting a gray tone from the Bg Color field in the Property inspector.
- Create a nested element by inserting a new AP Element within the existing BgAPElement AP Element. Name the new AP Element NestedAPElement.
- Insert Agnes's headshot image into the new NestedAPElement AP Element so the result resembles Figure 7.10.
Figure 7.10 Nest an AP Element within an existing AP Element.
It won't be overly obvious that the new AP Element is nested within the BgAPElement AP Element. However, you can see that the AP Element is in fact nested by looking at the AP Elements panel, also shown in Figure 7.10. As you can see, the NestedAPElement AP Element appears as a child node beneath its parent BgAPElement AP Element. The real benefit to nesting AP Elements becomes evident when you're working with Visibility properties. Because the default Visibility property of an AP Element is Inherit, the child AP Element always inherits the properties of its parent AP Element. What this means is that all we have to modify is the parent BgAPElement AP Element. Visibility changes made to this AP Element propagate down to all child AP Elements, effectively saving us from doubling our efforts.
Although it would seem logical that dragging a nested AP Element out of its container AP Element would unnest an AP Element, that isn't how you unnest elements. To unnest an AP Element, you must use the AP Elements panel to drag a child AP Element out of its current position and reposition it higher in the list in the AP Elements panel.
Deleting an AP Element
If you decide that a particular AP Element is no longer needed, you can easily delete it using one of two methods. The easiest way to delete an AP Element is to select it on the page and press the Delete or Backspace key on your keyboard. This action effectively removes the AP Element and its content from the document. The second option for deleting an AP Element from the Document window is to right-click (Control+click) the <div> tag in the Tag Selector and choose the Remove Tag option from the context menu. This action removes the <div> tag but does not remove the content from the Document window. The same holds true if you right-click the actual <div> tag on the page and choose Remove Tag <div>.