One of the biggest trends in web development is that of designing websites that don't use antiquated tables to control the structure of the site, but instead rely on layers and CSS positioning to control the layout and flow of web pages. In the next few sections, you'll learn how Dreamweaverin conjunction with the <div> tag and a little CSScan create standards-compliant web designs. NOTE The term given to the process used for creating CSS-based page designs in known as CSS-P. Designing Layers Using a Style SheetIn the previous sections of this chapter, you learned how easy it was to insert layers using either the Insert, Layout Objects, Layer command or the Draw Layer option available from the Layout category in the Insert bar. Although these are viable options for designing a site using layers, they aren't the best choice. The reason for this is simple: When you use either of these methods to insert layers on the page, Dreamweaver automatically assigns document-wide CSS positioning properties for each layer. As a result, the page becomes inflexible and nearly impossible to modify globally when numerous pages exist within the site. A better alternative to inserting or drawing layers onto the page is to create an external style sheet (which we already have for our project) and define numerous ID selectors that define the various divisions of the page. For instance, we know our site will contain the following major divisions based on the design we've been working with up to this point:
Now that we've outlined the major sections for our page, let's begin outlining the CSS rules. Because we know we'll have at least three major sections in the page (Header, Nav, and Content), we can surmise that we'll need at least three CSS rules represented by three unique IDs titled header, nav, and content respectively. To begin creating these selectors, follow these steps:
That's it! You're now ready to define the style rules for the remaining layers. To define the Nav rule, follow these steps:
To finish up the design, let's define the Content style rule:
Now that we've outlined the properties for the three major sections of the site, we're ready to insert the <div> tags that will act as containers for the content. The properties we've outlined will serve as the formatting and positioning attributes for the <div> tags we'll add next. Inserting DIV TagsNow that the style rules have been defined for each section of the page, we can start adding the <div> tags that will serve as containers for our content. Because we've already outlined the style rules using ID selectors in an external style sheet, we need only to insert three <div> tags into the page with IDs that match the ID selector names we created. To demonstrate this, let's insert a <div> for the Header portion of our page. You can do this by clicking the Insert Div Tag icon located second from the left in the Layout category in the Insert bar. Clicking this icon launches the Insert Div Tag dialog (see Figure 11.14). Figure 11.14. Use the Insert Div Tag dialog to create a new <div> tag in the page.Although the dialog allows you to enter a class name and pick an insertion point for the tag, all we care about is entering the ID name that represents the ID selector we've defined within our style sheet. Because we're creating the header of the page, select the Header option from the ID drop-down menu and click OK. The layer is created, complete with the dimensions, placement properties, and the background image we defined. By default, Dreamweaver adds the text Content for id "Header" Goes Here within the layer. Select this text and delete it so that we can add the header.gif image into the layer. When you've deleted the text, drag the header.gif image, located in the Images folder, into the layer. The result of the design resembles Figure 11.15. Figure 11.15. Add the header.gif image into the Header layer.Now you're ready to create the second <div> tag that will define the navigation layer. To do this, click the Insert Div Tag icon located in the Layout category of the Insert bar. When the Insert Div Tag dialog appears, select the Nav option from the ID drop-down menu and click OK. As you'll see, the Nav layer is added just below the Header layer. Again, remove the Content for id "Nav" Goes Here text so that we can begin to define the navigational elements that will appear within this layer. When the placeholder text is deleted, let's add the first navigation element, Home, to the layer. Do this by following these steps:
Now you can add the rest of the navigation elements: HelpDesk (helpdesk.htm), Company Directory (companydirectory.htm), Employee Store (employeestore.htm), and Admin (admin.htm). When you finish adding the navigation items, the result appears similar to Figure 11.16. Figure 11.16. Add the rest of the navigational elements to the Nav layer.Finally, let's add the content layer. Again, you can accomplish this task by clicking the Insert Div Tag icon in the Insert bar. When the Insert Div Tag dialog appears, choose the After Tag option from the Insert menu, choose the <div > option from the menu that becomes enabled, and choose the Content option from the ID drop-down menu. Click OK. The new layer is added below the Header layer but just to the right of the Nav layer. With the layer firmly in place, you can add the content that will fill that area. For instance, you might want to add the subheader_about.gif image as the subheader within the layer. You might also decide to add the text contained in the welcome.txt file in the Assets folder. Next, you might want to add the intranetsymbolism.gif image so that it appears as though the text wraps around it. When you've finished, the result should closely resemble Figure 11.17. Figure 11.17. Add text and images to the new Content layer.With your design complete, test the page in a browser by choosing the Preview in Browser option from the Document bar or by pressing F12. As you'll see, the design renders without problems (refer back to Figure 11.1). Of course, our design efforts don't have to stop here. We might want to create another layer with associated properties for our company events. Furthermore, we might want to add yet another layer with associated properties for the footer of the page. As you can begin to see, the design and implementation is simple. Even better than the implementation is what has been added to the HTML. Switch to Code view. And notice that the code is much cleaner and is minimized to roughly 15 lines of code as opposed to the 100 or so lines which was the case when we were working with tables. Converting Layers to Tables for Backward CompatibilityIn the previous sections, we used layers to create a standards-compliant, table-less web page. Although the design was simple to create, it doesn't do us or our users much good if they're using older browser versions such as Netscape 4.x. As you saw back in Figure 11.2, the page doesn't look very good in Netscape 4. To solve this problem, we have to re-create the site using a backward-compatible model in tables. Before you become frustrated at the thought of having to rebuild the page using tables, know that there's any easy and automated way of accomplishing this task in the Convert Layers to Tables feature. Using this feature in conjunction with the Check Browser behavior, we can guarantee that our users will see the appropriately formatted page regardless of what browser version they are using. To run through this process, choose Modify, Convert, Layers to Table. The Convert Layers to Table dialog appears, similar to Figure 11.18. Figure 11.18. The Convert Layers to Table dialog facilitates the process of converting our layers-based design to one that uses tables.The following functionality is exposed in the Convert Layers to Table dialog:
The rest of the features in this dialog exist for the reverse process (that is, converting tables to layers). In this scenario, these check boxes merely provide viewable options such as the Layers panel, the Grid, snapping, and so on. When you finish making the necessary adjustments, click OK. Immediately, our layers-based page is converted to a table with a few minor discrepancies. For instance, it seems as though we lost our background image for the header. To add it back in, simply place your cursor in the cell and use the point-to-file icon in the Bg field to browse to the header_bg.gif image. Finally, save your work as index_netscape.htm. Now try testing the page in an older version of Netscape. NOTE If you don't have an older version of Netscape, you can download all archived versions at the following URL: http://wp.netscape.com/download/archive. As you can see from Figure 11.19, the page looks as it did in newer browser versions using layers. Figure 11.19. The page using tables looks as good in Netscape 4.7 as it did in newer browser versions using layers.The last thing you'll want to do is add the Check Browser behavior to the index.htm page. This behavior allows us to create functionality such that when the user visits the index.htm page using a Netscape 4.x browser, the user is automatically redirected to index_netscape.htm. However, if users visit the index.htm page using a newer browser model, the users stay right where they are, on the layers-based index.htm page. To add this behavior, follow these steps:
With the layers-based page still open, try to preview your page in Netscape 4.7. Notice that you are automatically redirected to the index_netscape.htm page. |