19 November 2012
Before starting this tutorial, read and complete the steps in Part 1: Setting up your site and project files
Beginning
Welcome to Part 2 of this six-part tutorial series on creating your first website. This tutorial explains how to create a CSS-based page layout in Adobe Dreamweaver CS6. A page layout determines how your page will appear in the browser, showing, for example, the placement of menus, images, and other kinds of content.
Note: This tutorial series is intended for use with Dreamweaver CS6. If you are using an earlier version of Dreamweaver, some features might differ, particularly in the Document window and dialog boxes.
Laying out web pages with CSS (Cascading Style Sheets) has become the standard for modern web design. CSS offers superior flexibility and control over your layout, enabling you to create elements on the page and fine-tune their positions with pixel precision. However, CSS layouts can be difficult to understand and create, and it helps to have some background knowledge before building your first layout with CSS. You can start by reading CSS page layout basics, which is an overview of how CSS layouts work. But this reading is not required. If you're up for the challenge, you can just dive right into this tutorial to begin creating your first CSS-based layout.
Note: Although Dreamweaver CS6 has 18 predefined CSS layouts that you can use as the starting point for your web pages, I’m not going to use them in this tutorial series because I think it's important to experience what it's like to build a page layout completely from scratch. For more information on the predefined layouts, which were originally designed for Dreamweaver CS5, refer to What’s new in the Dreamweaver CS5 CSS layouts by Stephanie Sullivan Rewis.
Typically, you don't begin building a website by opening Dreamweaver and laying out pages. The first steps to creating a website begin on a piece of paper or in a graphics-editing application such as Adobe Fireworks or Adobe Photoshop. Graphic designers usually sketch out a piece of comprehensive artwork (also known as a comp) for the website to show it to the client and make sure that the initial ideas for the site meet with their client's approval.
A comp consists of any number of page elements that the client has requested for a website. For example, the client might say, "I want to have a logo at the top of the page, a navigation bar that links to these other pages, a section for an online store, and a place where I can insert video clips." Based on that discussion, the designer begins planning the layout of the site and creates sketches of sample pages that fulfill the client's requirements.
This tutorial provides you with the completed and approved comp for the home page of Check Magazine, a fictional publication that is in need of a website (see Figure 1). As the web designer, your job is to transform the comp into a working web page (most likely with the help of other graphic designers).

You'll notice that the graphic designer has provided you with a web page comp that includes a number of content areas, as well as some graphic ideas. Note also that the text is lorem ipsum text (fake Latin placeholder text) and that the headings in the bottom columns are not final (two of them are identical). Even though the page content is unknown at this point, you can still use Dreamweaver to lay out this design.
You can also open the original comp file if you want to see it in more detail. You can find the comp, check_comp.jpg, in the check_cs6/images folder that you copied to your hard drive in Part 1 of this tutorial series. You might even want to print the comp so that you can have it in front of you as you build your page.
More and more people are accessing websites on a wide range of screen resolutions from mobile phones through tablets to laptops and desktops. Creating a website design that adapts to different screen sizes requires considerable CSS knowledge and skills. To keep this tutorial relatively simple and focused on creating your first website, you’ll work with a fixed-width display designed for a desktop.
When learning new techniques or working with unfamiliar software, it’s easy to make mistakes. The instructions throughout this tutorial series try to anticipate common errors, and each part contains a ZIP file showing how the code should look when you have finished. If your page doesn’t look the way you expect, use the Dreamweaver File Compare feature to compare your files with the download versions. To use File Compare, you need a third-party file comparison utility, such as WinMerge for Windows. On a Mac, you can use the file comparison tool in TextWrangler. Both are free.
The most common causes of mistakes are accidentally skipping a step in the instructions and mistyping an ID or CSS property. Retrace your steps to see where you might have gone wrong. Sometimes, the best idea is to start again from scratch. It can be frustrating, but you can learn a great deal from your mistakes.
Of course, if you do get stuck, ask for help. The best place is in the Dreamweaver General Discussion Forum, where you’ll find experts and beginners alike helping each other.
Above all, enjoy yourself. Web design can sometimes be challenging, but it’s also a lot of fun.
After you have set up a site and examined your comps (if any), you are ready to begin building web pages. You'll start by creating a new page, and saving it in the check_cs6 local root folder of your website. The page eventually becomes the home page for Check Magazine.
Note: If you haven't created the check_cs6 local site folder, you must do so before you proceed. For instructions, see Part 1 of this tutorial series, Setting up your site and project files.

<none> from the Layout list (these two options should already be selected by default).Note: HTML5 is the new standard of the markup language for web pages. Although the standard hasn’t been finalized, the HTML5 DocType is backwards compatible with all web browsers in current use, including Internet Explorer (IE) 6. The only caveat is that you should avoid using the new semantic HTML5 tags, such as <header> and <footer>, because they aren’t recognized by IE 6 through IE 8. I’ll explain more about semantic tags later.
check_cs6 folder that you defined as the site's local root folder. Dreamweaver should have selected this automatically, but if a different folder is selected, click the Site Root button at the bottom of the dialog box (it’s on the right in Windows, and on the left in the Mac version).
This is the title of your page (different from the file name). Your site visitors will see this title in the browser’s title bar when they view the page in a web browser.
If you did the background reading recommended at the beginning of this tutorial (CSS page layout basics), then you already know that the <div> tag is the basic building block of a CSS layout. A <div> tag acts as a container for text, images, and other page elements, grouping them together so they can be styled in a consistent way. You use CSS to position them by adding horizontal and vertical space around them (margins) or inside them (padding). Compared to table cells, which exist only within the rows and columns of a table, <div> tags are much more flexible.
If you look at the design comp again (see Figure 1), you'll notice that the page is divided into distinct sections: a banner logo at the top of the page, a central graphic area in the center of the page, and then a third bottom section that contains three separate columns within it. These sections all correspond to separate <div> tags that act as containers for the content inside of them.
HTML5 adds new tags—such as <header>, <footer>, and <article>—that perform exactly the same function as a <div>. The only difference is that the new tags specify the role of the element in the page. Unfortunately, IE 6 through IE 8 won’t style the new tags with CSS unless you use JavaScript. To avoid problems with older browsers, this tutorial uses only <div> tags to group content.
Start by creating the most basic, most important, and most common <div> tag for CSS layouts—the container. The container <div> contains all the other tags in the layout. If your CSS layout is like a sandbox, and you are going to place a beach ball, a bucket, some shells, and an umbrella in the sandbox, then the container tag is the outer rim of the sandbox. It defines the shape, dimension, and limitations of the sandbox, and holds everything together.
In this section, you’ll work in both Design view and Code view because it’s important to understand the underlying HTML code that Dreamweaver creates on your behalf.


<div> tag’s ID gives it a unique identity that will be used to apply CSS styles to it later.The new <div> appears on your page, surrounded by a dotted line in Design view, and with some placeholder text inside (see Figure 6).

Note: If you can’t see the dotted line surrounding the <div>, choose View > Visual Aids, and make sure there’s a check mark alongside CSS Layout Outlines. Clicking any of the options in the Visual Aids submenu toggles them on and off.
<div> disappears, repeat step 4. The placeholder text should be automatically selected when the <div> is inserted, so all you need to do is to press Delete.<div>. At the moment, the only candidates are the <body> tag and <div id="container">.You want to nest the new <div> inside the container <div>, so select <div id="container"> (see Figure 7).

The new <div> appears on your page, and within it you can see the placeholder content for the header <div>. But where did the container <div> go? Well, it's there, you just can't see it in Design view. The best way to see it is to look at the code.

Split view displays the underlying code on the left of the Document window. You can see the container <div> tag, and inside it is the new header <div> tag, just as planned (see Figure 9).

Note: Working in Split view (formally called "Code and Design view") is a great way to learn how Dreamweaver generates code. When you insert something in Design view, you see the code that Dreamweaver writes in Code view. It’s particularly useful if you have a large monitor, because you can see the web page in Design view and the underlying code both at the same time.
Place the Insertion point after the closing </div> tag of the header <div> and press Enter (Windows) or Return (Mac OS X) to create a new line (see Figure 10).

Note: Pay careful attention to where you create the new line. You should still be inside the container <div>. The closing tag of the container <div> is on line 12 of Figure 10.
The new <div> appears on your page, and within it you can see the placeholder text. This new <div> is inside the container <div>, on the same level as the header <div>.
Note: When you create new IDs watch out for extra space either before or after the ID. For example, make sure that when you type the main_image ID, there is not an extra space after the "e" in image. If there is, it can lead to CSS problems later.
<div> you have just created and press Enter (Windows) or Return (Mac OS X).<div> elements. Give the first one the ID center_column, and the second one the ID right_column.Your code should now look as shown in Figure 11.

All your <div> elements are stacked one on top of another and stretch the full width of the page. This is the default behavior until you create CSS rules for them.
Now that you have your <div> tags in place, the next step is formatting and positioning them with CSS—a collection of formatting rules that control the appearance of content on a web page. Using CSS to format a page separates content from presentation. The content of your page—the HTML code—resides in the HTML file, and the CSS rules defining the presentation of the code reside in another file, the external style sheet.
You can also put CSS rules in the head section of a document, or inline with the code itself. However, an external file is the most efficient way of using CSS, because changes made to rules in an external style sheet are automatically applied to every page attached to it.
Dreamweaver has several tools that speed up styling your web pages. In this section, you’ll type the style rules directly into a style sheet to give you a feel for what CSS looks like. Don’t worry if you’re not keen on working directly with code. As you type, Dreamweaver displays code hints and auto-completes much of the code for you.

Note: CSS selectors are case-sensitive. The spelling of the ID must be the same as you used when inserting the <div> tag. So, if you used an initial capital letter, the CSS selector would be #Container. Also, make sure there’s no space between the hash sign and the ID.
#container {
width: 968px;
background: #FFF;
margin: 0 auto;
padding-left: 10px;
padding-right: 10px;
overflow: hidden;
}
As you type, Dreamweaver uses code hints to suggest options for completing your entry. Press Enter (Windows) or Return (Mac OS X) when you see the code you want, and let Dreamweaver finish the typing for you.
When typing the pixel values, do not leave a space between the number and px. For example, it must be 968px, not 968 px.
Don't forget to include a semicolon at the end of each line, after the property values.
When you're finished, the code should look as shown in Figure 13.

Each of the properties in your new rule means something specific for the container <div>. The first one—width—is the most obvious. It sets the width of the container div to 968 pixels. You are setting the background color to white (#FFF), and declaring 0 pixels for the top and bottom margins of the container, and auto for the left and right margins of the container. (This effectively centers the container in the middle of the page when the user views it in a browser.) For the padding, you've specified 10 pixels on the right and the left, and you've specified a hidden overflow, which forces large assets like images to stay within the confines of their container tags.
Note: For more information about CSS properties, check the O'Reilly reference guide included with Dreamweaver. To display the guide, choose Help > Reference and select O'Reilly CSS Reference in the Reference panel. This contains details of CSS2, plus some non-standard CSS properties.
Next you'll attach the new style sheet to the index.html page.
To attach the style sheet, follow these steps:
index.html page and make sure you are looking at the page in Design view. (If you're still in Code view, click the Design view button.) Your page should look exactly like Figure 14.
Even though you created a complex CSS rule for the container <div>, the page still looks the same as before. This is because the CSS style sheet is not yet attached to the page. When you attach the style sheet to the page, the #container rule that you created in the style sheet will format the <div> with the ID "container" on your web page.
You'll notice that the CSS Styles panel is empty except for the message, "(no styles defined)" because there are no CSS rules applied to this page.

check_cs6.css style sheet that you created in the styles folder, select it, and click OK (Windows) or Choose (Mac OS X).Note what happened to the page. You can immediately see that the container <div> now has padding of 10 pixels on the left and right. Depending on the size of your Document window, you might also see that the container <div> looks centered on the page. That's because if you have extra room (in addition to the 968-pixel width you specified), the container will also have an "auto" margin on its left and right sides. This effectively means that the browser will create exactly the same amount of pixel space to the left and right of the container <div>, thus producing a centered effect.
<div> until you see a red line, and then click to select the container <div>. Figure 16 shows what you should see when the container div is selected.
Note: If you have difficulty selecting the border of the container <div>, click inside any of the <div> elements you have created, and select <div#container> in the Tag selector at the bottom of the Document window.
Here Dreamweaver is giving you a nice visual rendering of how the CSS rule applies to the container element. The light gray shading on the left and right sides of the container <div> indicates the 10-pixel padding, and when you hover your cursor over the area, Dreamweaver displays a tooltip that tells you that. Similarly, the lighter blue areas at the outermost left and right sides of the container indicate the auto margins. Again, the amount of auto margin that displays in Dreamweaver depends on the size of your Document window. If you are working in the default Designer workspace, and you make your Document window smaller by dragging the docked panel area on the right, you should see the auto margin disappear as less space becomes available on the page.
Note: If the visual rendering of the padding and margins fails to display, choose View > Visual Aids, and make sure the following options are selected: CSS Layout Box Model and CSS Layout Outlines.

This turns on Live View in the Document window. The dotted outlines of the <div> elements disappear, and you see the page as it would look in a browser. In fact, you are looking at the page in a browser—Live View uses the WebKit browser engine that powers Safari and Google Chrome browsers.

<div> elements in the center of the page. As you move up or down, each <div> is highlighted in light blue.
This highlights the container <div>. The <div> itself is highlighted in blue. The 10-pixel padding on either side is highlighted in purple, and the auto margins are highlighted in yellow. When you can see the effect of your style rules like this it is much easier to understand how they change your layout.
check_cs6.css style sheet.Now that you have all your structural elements in place and your style sheet is attached to the page, you are ready to start adding content and styling it. For this project, you’ll start with the header content, which consists of the name of the magazine (Check), a tag line, and the navigation menu.
Until quite recently, it was common to use an image for the main banner heading of a website because browsers rely on the fonts installed on the visitor’s computer to render text. As a web designer, you might have many fonts installed on your computer, but you can’t rely on everyone else having as many. Consequently, you were restricted to a limited range of "web-safe" fonts. The situation has changed thanks to all browsers now supporting fonts that can be embedded in a web page. So, instead of using an image for the header banner, you’ll use HTML and style it with CSS and a web font.
Dreamweaver makes it easy to create headings and paragraphs using the correct HTML markup.
<div>.
<div> is now displayed in a large, bold font. Select it, and replace it with the single word Check.
The word "Check" is wrapped in <h1> tags, which make it a top-level heading. The second line is wrapped in <p> tags, which make it a paragraph. Design view gives both lines some basic styling to indicate what they will look like in a browser. At the moment, they’re nothing like the final design, but you’ll get to that later.
One of the most common ways of creating a navigation menu is to use a bulleted list—or unordered list, as it’s called in HTML—and style it with CSS.
<p> </p>
<ul>
<li>Features</li>
</ul>
The <ul> tags tell the browser to create an unordered list. The <li> tags are wrapped around each list item.
<li> tags in the underlying HTML. Type Fashion in Design view.
<div>. If you accidentally created a paragraph at the end of the list, press Ctrl+Z (Windows) or Cmd+Z (Mac OS X) twice to remove it.# in the Link field of the Property inspector.<ul>
<li><a href="#">Features</a></li>
<li><a href="#">Fashion</a></li>
<li><a href="#">Lifestyle</a></li>
<li><a href="#">Calendar</a></li>
<li><a href="#">News</a></li>
</ul>
The text of each list item is wrapped in an <a> tag, which turns it into a link. The href attribute normally contains the address of the page that’s the target of the link, but the hash sign makes it a dummy link.
Images can be added to a web page either directly in the HTML using the <img> tag or as a background image using CSS. By default, browsers turn off background images when a page is printed. If an image is important, you should put it directly in the HTML markup. However, text will be added in front of the main image in this layout, so I think it’s fine to use CSS to insert it as a background image to the main_image <div>.
This time, you’ll use the New CSS Rule and CSS Rule Definition dialog boxes to create the necessary style rule.
<div>, and delete all the placeholder text.<div> has completely disappeared. Don't worry, it's still there. Check in Split view that the insertion point is between these two tags:<div id="main_image"></div>
As long as your Insertion point was in the main_image <div> when you clicked the icon, the New CSS Rule dialog box should automatically suggest appropriate settings for the CSS selector (see Figure 25).

Dreamweaver detects that the Insertion point is in the main_image <div>, which is nested inside the container <div>, and it suggests using the compound selector #container #main_image. The text area below the Selector Name describes the meaning of this selector.
Although it’s correct, everything in the page is nested inside the container <div>, so you don’t need to be so specific.
#main_image, which is exactly what you want.check_cs6.css is selected from the Rule Definition pop-up menu. Then click OK.#main_image rule. images folder inside the Check Magazine site.The main.jpg graphic is now defined as the background image for the main_image <div> (see Figure 26).

Figure 27 shows what your page should look like at this point in Design view.

The last major task for the basic layout of index.html is to marshal into order the columns at the bottom of the page. CSS categorizes most HTML elements as block-level or inline. A block-level element begins on a new line of its own, and forces the following element onto the next line, whereas inline elements snuggle up alongside each other. Typical block-level elements include headings, paragraphs, and <div> tags. Text inside a paragraph and images are inline elements.
Before moving the columns into position, you need to do a little calculation. The main image is 968 pixels wide. That doesn’t divide evenly by 3, but you need a little breathing space between each column, say 10 pixels. So, if you divide 948 by 3, you get 316. That’s how wide each column needs to be. It also happens to be the width of the images at the top of each column.
check_cs6.css in the Related Files toolbar just below the tab for index.html. This opens the style sheet in Split view, while leaving index.html visible in Design view (see Figure 28).
You can now edit the style sheet, and see the changes in Design view.
Note: If you’re cramped for space, drag the center bar to resize the windows. You can also make extra room by pressing F4 to hide all the panels. Press F4 again to restore them.
<div> elements. Add the following style rule at the bottom of the style sheet:#left_column, #center_column, #right_column {
width: 316px;
}
Note: Code hinting in Dreamweaver CS6 is remarkably smart. It recognizes unique character combinations within CSS properties. Instead of typing widt before Dreamweaver selects width, just type dt to jump straight there, and then press Enter (Windows) or Return (Mac) to insert width: in your style sheet. This trick works with all code hints, not just CSS.
Separating the ID selectors for the three <div> elements with commas applies the same rule to each of them.
To get the columns to sit alongside each other, you need to use the float property.
float:. Then type l (lowercase L) to bring up the code hint for left (see Figure 29).
Press Enter/Return to insert left, and add a semicolon at the end of the line. The style rule should now look like this:
#left_column, #center_column, #right_column {
width: 316px;
float: left;
}
#center_column, #right_column {
margin-left: 10px;
}
Like the previous style rule, the same property is assigned to multiple elements by listing their selectors separated by commas.
Note: Depending on where the focus is in the Document window, Save All Related Files might be grayed out. If it is, choose Save All. The difference is that Save All saves all files that are currently open. Save All Related Files saves only those files that are related to the current document.
Figure 30 shows what your page should now look like in Design view.

Your CSS page layout is now complete. If for some reason your layout does not look the way it's supposed to, double-check the spelling (including capitalization, if appropriate) of all your CSS rules. The most common causes for CSS layout errors are typographical ones, so you must make sure that the IDs in your external CSS file correspond exactly to the IDs in your index.html file. Also, don't forget to watch out for those extra spaces that can creep in before and after IDs when creating new CSS rules.
Now that you've finished the basic structure, you're ready to start bringing the page to life in Part 3: Styling the header and navigation menu.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.
Comments are currently closed as we migrate to a new commenting system. In the interim, please provide any feedback using our feedback form. Thank you for your patience.
Tutorials and samples |