tag’s vertical and horizontal center point (circled in this figure). If you mouse over the border, margin, or padding, a yellow box appears listing the values for those properties, in this case a 25 px bottom margin, a 1px bottom border, and 8px of bottom padding.
As you can see, there’s a considerable amount of margin on the bottom and a small amount of padding (8 pixels’ worth) applied to the top, left, bottom and right edges. If you find these visual aids confusing, you can turn them off via the Visual Aids menu in the document window (see Figure 9-12) or by choosing View→Visual Aids→Layout Box Model. These same steps turn the margin and padding visual aids back on.
When Width Doesn’t Equal Width In my style sheet, the CSS Width property of one of my styles is 150 pixels. But when I preview the page in a web browser, the
tag I applied the style to is much wider than 150 pixels. Is there a bug in my browser? No, you’re browser is fine. The problem lies with the difference between the CSS width property and the final calculated width of an element onscreen. The width you see onscreen is the sum total of several separate CSS properties, not just the Width property. The Width property merely defines the width of the content area of the style—the place where the text, images, or other nested tags sit. The actual width—that is, the amount of screen real estate assigned by the web browser—is the total of the widths of the left and right margins, left and right padding, left and right borders, and the Width property. So say you create a style with a width of 100 pixels, 10 pixels of padding on all four sides, a 2 pixel border, and 20 pixels of space in the left margin. While the space dedicated to the content inside the style is 100 pixels wide, any tag with this style will have an onscreen width of 144 pixels: 100 (width) + 10 (left padding) + 10 (right padding) + 2 (left border) + 2 (right border) + 20 (left margin).
around all other page elements. Its width is 960 pixels, so everything inside that div must fit in that 960-pixel space. If you wanted to create a four-column layout, you might insert four divs and create styles that set the width of each to 240 pixels (960 divided by 4). However, if you added even a 1-pixel border to one of the divs, they’d suddenly take up more than 960 pixels, and you’d find that the last column wouldn’t fit—in fact, it would drop down below the other three columns, creating a very weird-looking layout. So if you find yourself floating lots of elements, and one of them drops below another when it should sit beside it, odds are pretty good that the elements are just too wide to sit side by side. So decrease the width, margins, padding, or borders until the elements fit (breaking out a calculator and adding up the margins, padding, borders, and widths can also help). The CSS Height property and the final height of a style behave the same way. The onscreen height of an element is a combination of the height, top and bottom margins, padding, and borders.
This can cause problems if you’re not careful. For example, in a fixed-width layout, you might create a div that wraps
Dreamweaver’s CSS Layouts You’ll contend with many details when you build CSS-based layouts. For example, you need to understand the intricacies of the CSS Box Model, as well as the sometimes-bizarre behavior of floats. In addition, different browsers handle some CSS properties differently, which sometimes means a design that looks great in Firefox but completely falls apart in Internet Explorer 6. (Remember, even though much of the Windows-loving world has upgraded to IE 8 and IE 9, there are still plenty of folks cruising around the Web in IE 6 jalopies.) Fortunately, Dreamweaver is ready to give you a helping hand with 18 predesigned CSS Layouts.
452
Dreamweaver CS6: The Missing Manual
Dreamweaver’s CSS Layouts aren’t finished web page designs. They don’t have graphics, fancy text, drop-down menus, or any whiz-bang features. They’re basic designs intended to lay the foundation for your design talents. Each layout is a simple HTML file and style sheet, each works with all current browsers, and each design’s handcrafted CSS code irons out the many wrinkles in troublesome browsers (most notably Internet Explorer 6). In other words, instead of spending a day stretching and sizing your own canvas, a Dreamweaver CSS Layout is like going to the art store and buying a ready-made and primed canvas so you can get busy painting.
Dreamweaver’s CSS Layouts
Creating a new CSS layout page takes just a few steps: 1. Choose File➞New. This is the same first step you take when creating any new web page. The New Document window appears (Figure 9-13). You can also use the Ctrl+N (c-N) keyboard shortcut to open this window (however, it’s possible to disable this keyboard shortcut, as described on page 47; you might want to do that if you’d rather skip this clunky window whenever you just want a new, blank web page).
CSS layouts
Selected layout
Preview
Figure 9-13
This Blank Page New Document dialog box lists Dreamweaver’s readymade CSS Layouts. For example, “2 column fixed, right sidebar, header and footer” indicates a design with 2 columns: the main content column on the left, and a thinner sidebar (for supplementary info like links) on the right. The design also sports a fixed width and has header and footer divs. A preview of the selected layout appears in the top-right of the window; a brief description below the preview provides more detail on how the layout works.
2. Choose Blank Page from the left column, and the type of page you wish to create in the Page Type column. Usually, you’ll select HTML from the Page Type category, since most of the time you’ll create regular web pages. However, if you’re creating a page that uses a server-side language like PHP, you’d select it from the list.
Chapter 9: Page Layout
453
Dreamweaver’s CSS Layouts
Tip The Page From Sample category in the left column of the New Document window (see Figure 9-13) is
mostly useless. It includes sample pages with some rudimentary design, but you can write better style sheets on your own. However, Dreamweaver CS6 includes a “Mobile starters” category for creating mobile sites (see on page 537 for a discussion of this feature).
3. From the Layout column, select a page layout. This is where the fun begins. As you’ve read before, choose <none> here to create an empty web page. The other options, however, let you choose one of 18 prefab CSS-based layouts. Basically, you decide how many columns you want (one, two, or three), whether you want a header and footer (like a banner at the top or a copyright notice at the bottom), and the type of web page layout (fixed-width or liquid). A fixed-width design maintains a constant page width no matter the width of a visitor’s browser window. A liquid design lets the overall width of the page change with the size of a browser window. See page 435 for more on these types of layout. Dreamweaver previews each design in the top-right of the New Document window. See Figure 9-14 to decipher the visual codes that help you understand how the layouts behave.
Figure 9-14
The layout previewed in the Blank Page New Document window visually identifies the type of CSS layout you select. A small lock icon indicates a fixed-width design (top); the layout sets the width of each column using pixel values, and the widths don’t change when a guest resizes her browser window. The % symbol indicates a liquid design (bottom). It defines column widths using percentage values that change based on the width of the browser window; a wider browser window means wider columns. Liquid designs fill the entire width of a browser (well almost—the liquid designs provided with Dreamweaver are actually 80% of the width of the browser window).
4. Choose a doctype from the DocType menu. Here’s where you decide which type of HTML/XHTML you want to use for the page. It’s the same option you face when you create a new, blank web page, as described on page 46. You’re safe going with the default option of HTML5.
454
Dreamweaver CS6: The Missing Manual
5. From the Layout CSS menu, select where you want to store the layout’s CSS code.
Dreamweaver’s CSS Layouts
Each Dreamweaver CSS Layout requires its own style sheet of all the styles that make the layout work. When you create a new page from a CSS Layout, you can store that style sheet several places. The “Add to Head” option creates an internal style sheet in the HTML file Dreamweaver creates. Most of the time, you don’t want this option, since external style sheets are more efficient (see page 123 for an explanation). You can also store the CSS Layout styles in a new, external style sheet. Choose Create New File to let Dreamweaver store the necessary CSS rules there. You choose this option when you first use one of Dreamweaver’s CSS layouts to create a new page. This creates a separate file with all the CSS necessary to control the page’s layout. To add another page to your site using a layout you’ve already used (for example, a two-column fixed design with a header and footer), read on. The “Link to Existing File” option sidesteps the entire process of creating new CSS styles. It assumes you have the appropriate styles defined in another external style sheet. If you previously created a web page using the same type of CSS layout, choose this option. Say you created a two-column fixed layout using a Dreamweaver CSS Layout. At that time, you saved the necessary styles for that layout in an external style sheet and saved the sheet to your site. Now, you can create a new two-column fixed-layout page using this external style sheet. Choose “Link to Existing File,” and then proceed to step 6 to link the external style sheet on your site. Keep in mind, however, that each CSS Layout has its own style sheet. So if you create a two-column fixed-layout page and then want to create a three-column liquid layout page, you can’t link to the style sheet Dreamweaver created for the two-column layout. In other words, whenever you create a new type of CSS layout (two-column fixed, three-column liquid, and so on), choose the Create New File option so Dreamweaver creates the appropriate CSS in a new external style sheet. Tip You don’t need to go through these steps each time you want to create a new page using a CSS layout you’ve used before. Suppose you want to build a 40-page site with two-column, fixed-layout pages. Instead of going through the New Document dialog box (and the steps listed here) 40 times, use the New Document dialog box to create the initial page, and then choose File→Save As to save a copy of that design for the next two-column page you want to create. Better yet, use Dreamweaver’s Template tool described in Chapter 19 to manage pages that have the same layout.
Chapter 9: Page Layout
455
Dreamweaver’s CSS Layouts
6. Click the Attach Style Sheet button to attach any external style sheets to the page (see Figure 9-15). This is an optional step, but if you already have an external style sheet you want to use to format your site, now’s the time to link to it. In addition, if you chose “Link to Existing File” in the previous step, you have to link to an external style sheet to create a particular layout type. The process of linking to external style sheets is the same as with any other web page, as described on page 138. Note If, when you create a new web page, you link to an external style sheet as described in step 6,
Dreamweaver may pop up a warning message that says something about needing to save your web page in order to correctly attach the style sheet. You can safely ignore this message. In fact, turn on the “Don’t show me this message again” checkbox so you don’t see this annoying message in the future.
Figure 9-15
You can attach more than one external style sheet when you create a CSS-based layout. One might define the basic look of headlines, text, images, and other elements, for example, while another controls column layout, and a third “printer” style sheet might dictate how the page will look when printed (see page 399).
7. Click the Create button to bring your new web page to life. If you selected the Create New File option in step 5, Dreamweaver asks you to name the new style sheet and select where you want to save it (just like when you create a new external style sheet, as described on page 128). Dreamweaver suggests names for the CSS files for each of its layouts—such as twoColFixRtHdr.css for a two column, fixed design with a right sidebar and a header and footer. You can change the name if you like, but the name Dreamweaver suggests is descriptive. After all of that, you end up with a page that has a basic structure and some instructional text telling you to fill in the different areas of the page (see Figure 9-16). Don’t forget to save and title the page.
456
Dreamweaver CS6: The Missing Manual
Dreamweaver’s CSS Layouts
Figure 9-16
It doesn’t look like much, but a CSS Layout page has the basic scaffolding of a bona fide web page in place:
tags to organize the page and CSS styles to position those divs. Click inside any area of the page, and the Tag Selector (circled) shows you the structure of the HTML at that point. In this case, if you click inside a paragraph in the middle column, the Tag Selector shows you which tags wrap around that paragraph. You read this info from right (the selected
tag) to left (the
tag that contains everything you see inside the document window). For this twocolumn design, the
tag is inside a div with a class of .content (that’s what the
means), which is itself inside a div with a class of .container. Finally, the tag encloses all the other tags.
The Structure of Dreamweaver’s CSS Layouts Dreamweaver’s CSS Layouts are made up of a handful of page elements: Some pages have a header and footer, others have one or two sidebars, and all have a section of main content. The layout circumscribes each section with a tag, and each div has its own class. The layout’s accompanying style sheet defines the class styles and controls where a browser positions the different divs on the page.
Chapter 9: Page Layout
457
Dreamweaver’s CSS Layouts
To keep the CSS Layouts consistent, Dreamweaver uses the same class names for every layout (see Figure 9-17). It calls the class for the
tag containing the main content; if the layout has a sidebar, Dreamweaver applies the sidebar class sidebar1 to it; if there’s a second sidebar, Dreamweaver calls it sidebar2. Likewise, the header div has a class of header, while the div at the bottom of the page is footer. Dreamweaver uses one other
, and it surrounds all the other divs: Its class is container. You may wonder: If all the CSS Layouts share the same names for their divs, how do you end up with different types of designs, like fixed and liquid? Each page has its own style sheet. When you create a new CSS Layout page and save those styles in an external style sheet (as described in step 5 on page 455), Dreamweaver suggests a name such as thrColFixHdr.css (for a three-column, fixed design with a header and footer), or twoColLiqRt.css (for a two-column, liquid design with a right sidebar). Each style sheet has different rules for its container, content, sidebar, and header, and footer styles. This means that if you plan on using more than one CSS Layout page, you need to keep separate style sheets for each type—in other words, if you attach the twoColLiqRt.css file to a three-column, fixed design, you end up with some weird results.
Figure 9-17
.container
Each Dreamweaver CSS Layout’s basic structure is the same. Several
tags identify the various regions of a page. Each div has its own class name, which a class style in the design’s style sheet controls.