Designing a blog with html 5


 

Much of HTML 5′s feature set involves JavaScript APIs that make it easier to develop interactive web pages but there are a slew of new elements that allow you extra semantics in your conventional Web 1.0 pages. In order to investigate these, let’s look at marking up a blog.

Firstly what we’ll do is use the headerfooterand nav elements to mark up the broad structure of the page. We’ll make the blog comments form much smarter by using the new data types and built-in validation available in HTML 5-aware browsers.

Then we’ll do some work on the guts of the page, using HTML 5’s article elements to better mark up blog posts and comments and show how to use the section elements to better structure accessible hierarchical headings on sites that are CMS-driven. As blogs are chronologically ordered, we’ll see what HTML 5 offers us for representing dates and times.

So take the phone of the hook, and make a cup of tea and we’ll get started.

Setting the DOCTYPE

HTML 5, when used as plain HTML rather than its XHTML 5 sibling doesn’t need a DOCTYPE. But all browsers do, otherwise they go into Quirksmode, which you don’t want: the collision of HTML 5 and Quirksmode is like matter and anti-matter meeting, and will cause a negative reality inversion that will make your underwear catch fire.

You’ve been warned, so at the top of your document, you need the line<!DOCTYPE html>.

Some sites “use” HTML 5, when in actual fact all they’ve done is take their existing code and change the DOCTYPE. That’s fine and dandy if you’ve been using valid, semantic code as HTML 5 is very similar to valid HTML 4.01. Eric Meyer mentions small differences like “not permitting a value attribute on an image submit”, and there are a few differences between the languages, summarised in the documentHTML 5 differences from HTML 4.

However, I don’t want simply to rebadge my existing code, but to use some of the new structural elements now.

Using some new structural elements

My blog – like millions of others – has a header denoted by <divid="header">, a footer <div id="footer">, some articles (wrapped by an area called “content”, <div id="content">) and some navigation (wrapped up in an area called “sidebar” <divid="sidebar">). Most sites on the Web have similar constructs, although depending on your choice they might be called “branding” or “info” or “menu”, or you might use the equivalent words in your own language.

Although these all have very different functions within the page, they use the same generic div in the markup. as HTML 4 has no other way to code them. HTML 5 has new elements for distinguishing these logical areas: headernavfooter and friends. (There’s more on this in an artice by Lachlan Hunt on A List ApartA Preview of HTML 5.)

The overall aim is to replace this structure:

structure chart before redesign

with this:

structure chart after redesign

It’s a simple matter to change the HTML divs into the new elements. The only difficulty I had was deciding which element to use to mark up my sidebar, as it also includes a search field and “colophon” information as well as site-wide navigation. I decided against the aside element, as the spec says it “represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content”, but it’s nevertheless content rather than navigation. So I decided to go for the nav element as the closest fit.

I’ve wrapped the main content in a section element (previously I’d kept it as a div). section is defined in the spec

The section element represents a generic document or application section. A section, in this context, is a thematic grouping of content, typically with a heading, possibly with a footer.

Please note: I no longer recommend wrapping the whole content area in a section element, and suggest that you use adiv element. Read more about using section appropriately.

In this case, the “generic document section” is that of main content. I’ve retained an id so that a skip links feature will work, although I hope that in the future, assistive technology will offer an automatic way for people to go to the first section or article.

My fellow HTML 5 doctor, Remy Sharp, also notes that if you retain the div, Internet Explorer without JavaScript would style the div, but none of the other content, making the site very hard to read.

New form attributes

As well as the main structural item on the page, I’ve added some new attributes on input elements in the comments form.

HTML 5 was designed to reflect what developers actually do rather than to reflect a philosophical purity, and that’s very clearly manifested in the new attributes which mean the browser takes up much of the work currently done by developers re-inventing validation routines in JavaScript. (Extending forms functionality was how the HTML 5 spec began).

So I amended the email input field in the comments to be input type="email" which means that when the user submits the form, anHTML 5-aware browser will use built-in validation routines to check that it’s in the correct format, without any JavaScript. Check it out in the current version of Opera, as that the only full implementation at the time of writing (June 2009), and note that it also adds a “mail” icon in the input field as a cue to the user.

There are similar input validation routines triggered by some of the new input types, such as url (which I use on the field that asks for the user’s web address), number and pattern which compares the input with an arbitrary regular expression.

Another good example is input type="date", which pops up a calendar widget/ date picker when the user focusses on the input field. You can test the date picker, or here’s a screenshot from Opera 9.6:

date picker pops up next to input field

A very useful new attribute I used on both input fields for commenter’s name and email address, and the comment textareawas type="required" which generates a message on submission if the fields are left blank. Each different localisation of a browser would need to have a different message, and it’s not (so far) customisable by the developer.

red-bordered browser message 'You have to specify a value' next to unfilled required field

The good thing with all this new form fabulousness is it’s all formed around new attributes on an existing element, so people using older browsers just see a plain old input field.

A note on screen-readers and HTML 5

I hope screen-readers are ready for these new interactions; I asked the html 5 group to formally invite screenreader vendors to participate in the specification; to my knowledge, none have done so.

Laying out the new elements

It’s not too hard to layout the new elements. In all the non-IE browsers, you can lay out anything using CSS – even a nonsense element. One gotcha is that that the current crop of browsers have no “knowledge” of these elements, although support is improving all the time.

All browsers have default settings for the elements they “know about”—how much padding, margin they element gets, does it display as a block or inline?. (Here’s a sample default stylesheet.) Unless over-ridden by CSS, these defaults apply. But the browsers don’t know about headernav and the like, so have no defaults to apply to them.

I got terrible rendering oddities until I explicitly told the browsers

header, footer, nav, article {display:block;}

IE layout

There’s one gotcha about styling HTML 5 pages in IE: it doesn’t work. You can force it to quite easily with a JavaScript hackdocument.createElement('element name'). (Lachlan Hunt gets to the bottom of why IE needs this.)

For your convenience, Remy Sharp has written an HTML 5 enabling script which I use in the header to conjure all the missing elements into existence all at once.

But let’s be clear: this won’t work if your IE user doesn’t have JavaScript turned on. How much of that’s a big deal that is for you to decide. Pragmatically, it seems to me that the sites that will benefit the most from HTML 5’s new “Ajax”-style features, such as drag-and-drop, are the sites that currently have no hope of working without JavaScript.

Firefox 2 and Camino 1 layout

Firefox 2 and Camino 1 both use Gecko 1.9 which has a bug and so gets grumpy if you don’t serve the page as XHTML. (Go figure; that’s almost enough to trigger a negative reality inversion and you know how bad that can be). However, Firefox and Camino users upgrade frequently so Firefox is in version 3, while Camino 2 beta is out, so the problem will soon cease to exist. (Read more at How to getHTML5 working in IE and Firefox 22 by Remy Sharp.)

What’s the point of those new structural elements?

Well, they add semantics to the page. The browser now knows which area of your site is the header or the footer because there are headerand footer elements, whereas div might be called “branding” and “legal”, or even “en-tete” and “pied-de-page” or “kopfzeile” and “fusszeile“.

But so what?

Robin Berjon expressed it beautifully in a comment on A List Apart:

Pretty much everyone in the Web community agrees that “semantics are yummy, and will get you cookies”, and that’s probably true. But once you start digging a little bit further, it becomes clear that very few people can actually articulate a reason why. So before we all go another round on this, I have to ask: what’s it you wanna do with them darn semantics?

The general answer is “to repurpose content”. That’s fine on the surface, but you quickly reach a point where you have to ask “repurpose to what?” … I think HTML should add only elements that either expose functionality that would be pretty much meaningless otherwise (e.g. canvas) or that provide semantics that help repurpose for Web browsing uses.

In my view, there are a couple of things I want to do with those semantics. The first is for search engine use; it’s easy to imagine Messrs Google or Yahoo! giving lower weighting to content in footer elements, or extra weight to content in the header. The second reason is to make the site navigable for people with disabilities. People with learning difficulties might instruct their browser always to put the articles before the navigation, for example. User agents might very well have a keyboard shortcut which jumped straight to the nav for example, or jumped straight past the navigation, in a programmatic implementation of “skip links“.

Which brings me to…

Further refining the HTML 5 structure

The blog home page

An interesting thing about a blog homepage is that there are generally the last 5 or so posts, each with a heading, a “body” and data about the post (time, who wrote it, how many comments etc.) and usually a link to another page that has the full blog post (if the homepage just showed an excerpt) and its comments.

HTML 5 has an article element which I use to wrap each story:

The article element represents a section of a page that consists of a composition that forms an independent part of a document, page, or site. This could be a forum post, a magazine or newspaper article, a Web log entry, a user-submitted comment, or any other independent item of content.

Let’s look in more detail at the guts of how I mark up each blogpost.

Anatomy of a blog post

diagram of article structure; explanation follows

The wrapper is no longer a generic div but an article. Within that is a header, comprising a heading (the title of the blogpost) and then the time of publication, marked up using the time element.

Then there are the pearls of wit and wisdom that consitute each of my posts, marked up as paragraphs, blockquotes etc., and is pulled unchanged out of the database. Following that is data about the blog post (category, how many comments) marked up as a footer and, in the case of pages that show a single blogpost, there are comments expressing undying admiration and love. Finally, there may be navigation from one article to the next.

Data about the article

Following the content there is some “metadata” about the post: what category it’s in, how many comments there are. I’ve marked this up as footer. I previously used aside which “represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content” but decided that it was too much of a stretch; data about a post is intimately related.

footer is a much better fit: “A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.” I was initially thrown off-course by the presentational name of the element; my use here isn’t at the bottom of the page, or even at the bottom of the article, but it certainly seems to fit the bill – it’s information about its section, containing author name, links to related documents (comments) and the like. There’s no reason that you can’t have more than one footer on page; the spec’s description says “the footer element represents a footer for the section it applies to” and a page may have any number of sections. The spec also says “Footers don’t necessarily have to appear at the end of a section, though they usually do.”

Comments

I’ve marked up comments as articles, too, as the spec says that an article could be “a user-submitted comment”, but nested these inside the parent article. The spec says

When article elements are nested, the inner article elements represent articles that are in principle related to the contents of the outer article. For instance, a Web log entry on a site that accepts user-submitted comments could represent the comments as article elements nested within the article element for the Web log entry.

These are headed with the date and the time of the comment and name of its author—if you want, you can wrap these in a header, too, but to me it seems like markup for the sake of it.

Times and dates

Most blogs, news sites and the like provide dates of articlepublication.

Microformats people, the most vocal advocates of marking up dates and times, believe that computer-formatted dates are best for people: their wiki says “the ISO8601 YYYY-MM-DD format for dates is the best choice that is the most accurately readable for the most people worldwide, and thus the most accessible as well”. I don’t agree (and neither do candidates in my vox pop of non-geeks, my wife, brother and parents).

I do agree with the micro formats people that hidden metadata is not as good as visible, human-readable data and therefore elected not to use the pub date attribute of article.

Therefore I’ve used the HTML 5 time element to give a machine parsable date to computers, while giving people a human-readable date. Blog posts get the date, while comments get the date and time.

The spec is quite hard to understand, in my opinion, but the format you use is 2004-02-28T15:19:21+00:00, where T separates the date and the time, and the + (or a -) is the offset from UTC. Dates on their own don’t need a timezone; full date times do. Oddly, the spec suggests that if you use a time without a date, you don’t need a timezone either.

There’s considerable controversy over the time element at the moment. Recently one of the inner circle, Henri Sivonen, wrote that it’s for marking up future events only and not for times tamping blogs or news items: “The expected use cases of hCalendar are mainly transferring future event entries from a Web page into an application like iCal.” This seems very silly to me; if there is a time element, why not allow me to mark up any time or date?

The spec for time does not mention the future event-only restriction: “The time element represents a precise date and/or a time in the proleptic Gregorian calendar” and gives three examples, two of which are about the past and none of which are “future events”. Although the spec doesn’t (currently) limit use of the element, it does limit format to precise dates in “the proleptic Gregorian calendar”. This means I can mark up an archive page for “all blog posts today” using time, but not “all July 2008 posts” as that’s not a full YYYY-MM-DD date. Neither can you mark up precise, but ancient dates, so the date of Julius Ceasar’s assassination, 15 March 44 BC is not compatible.

I don’t expect this to be resolved. If you think as I do, feel free to mail the Working Group to express your feeling!

Hopefully, this brief article has given you a quick overview of how to use some of the new semantic elements.

Advertisements

iWeb – Build A Quick, Easy & Beautiful Website [Mac only]


IWeb

Image via Wikipedia

 

Having recently discovered a way to get my own (unlimited) domain names and several good places where I could host them for free, I can’t help but falling into the mood of web building. And while I’m at it, I think this is the perfect time to try building one using Apple’s own iWeb 09.

This free Mac website building tool comes with iLife suite – free with every new Mac purchase. It promises its users quick and easy ways to build beautiful websites. To be able to achieve that, iWeb comes with various ‘plug and play’ ready-made templates for users to use and modify.

Experience is the best teacher. So there’s no better way to explore what iWeb can do than by using it to make use of our domain name and web host.

Settling on the Settings

The first thing that you’ll see when you first open iWeb is the choices of templates. Don’t worry too much at this stage. Just pick the one that you like, and you can change your mind later.

free mac website builder tools
Then we can continue with the settings. Click the “Site” item on the left pane, and you’ll see the “Site Publishing Setting” opened in the middle pane. This is the place to change the name of your site from “Site” into something more appealing.
free mac web tools

If you want to publish your site on your chosen hosting service, choose “FTP Server” from the “Publish to” options. (Note: This option is not available on the older version of iWeb). Then fill in all the fields with the required information; from the site name, to the FTP settings, to the website URL.

iWeb

For you Facebookers, there’s a bonus that you’ll love: the ability to update your Facebook profile when you publish your site. Tick the checkbox and provide the user information if you want to activate this option.

mac web design software

Shaping the Site

The web building process itself is as simple as adding pages (Command + N), editing the text, and replacing the pictures.

mac web design software

If you want to, you can edit every element of the page by clicking on that specific element and opening the “Page Inspector” from the “View –> Show Inspector” menu or by pressing “Command + Option + I

mac web design software

There are several types of pages that you can add, such as a blank page; ready to edit pages (Welcome Page, About Me page); blog page – where you can write and update your posts; and also the rich-media pages (Photo Album page, Movies page and Podcast page).

The pages will be placed in the left pane and you can re-arrange the order as you like. You can also add another website(s) (Command + Shift + N) to the project, each with its own pages and themes.

designing web pages in a mac

Enhancing with Elements

To enhance your site, you can add as many kinds of elements you want to each page. There are four tabs on the right pane:

    • Audios –> You can add music to your pages from Garageband and iTunes

designing web pages in a mac

    • Photos –> You can add pictures from iPhoto and Photobooth

designing web pages in a mac

    • Movies –> You can add movies from iMovie and iTunes

free mac web design programs

    • Widgets –> You can add several ready made widgets, including the one to include HTML code called HTML snippet widget

free mac web design programs

There are more advanced settings that you can do by going deeper into the Page Inspector, but the scope is too big to be discussed here. You can find many nice effects while you experiment with iWeb.

After the building process is done, you can do the final step by clicking the “Publish Site” button below. If you put the FTP settings right, everything should be uploaded to your server, and your site will be alive.

iWeb might not be the ultimate tool for those professional-level web designers. But for everyday folks who just want to build a beautiful site quickly and easily, this app is more than capable to fulfill their needs.

Have you tried iWeb? Got any tricks to optimize iWeb? Share using the comments below.

Adobe Dreamweaver CS5 – Part 6: Publishing your website


Adobe Dreamweaver CS4 logo

Image via Wikipedia

Welcome to the sixth and final part of this article series on creating your first website. This tutorial shows you how to set up a remote site in Dreamweaver. A remote site is usually a web server on a remote computer that holds copies of your local files. Users access the remote site when they view your pages in a browser.

This tutorial presents a very broad example of connecting to a remote server. It contains troubleshooting hints, but much depends on how your remote server is configured. When in doubt, consult your hosting company’s help desk or your system administrator.

Learn about remote sites

After you create a website, the next step is to publish it by uploading the files to a remote server. This is where you store your files for testing, production, collaboration, and publication (depending on your environment).

Before you can proceed, you must have access to a remote web server—such as a hosting company’s server, a server owned by the client you’re working for, or an intranet server within your company. Also, some Internet Service Providers (ISPs) provide access to free web space as part of your contract for internet connection. If you don’t have access to such a server, contact your ISP, your client, your system administrator, or one of the many hosting companies that provide web hosting packages. Some hosting packages are free, but usually insert advertisements into your site. An advertisement-free package can cost as little as a few dollars a month.

Alternatively, you can run a testing server on your local computer or network. For more information, see Setting up a local testing server in Dreamweaver CS5. The rest of this article concentrates on connecting to a remote server using FTP (file transfer protocol) or SFTP (secure file transfer protocol).

You also need to have a local site defined before you proceed. For more information, see Part 1 of this tutorial series,Setting up your site and project files.

Note: For more information about Dreamweaver sites, see Setting up a Dreamweaver site in Dreamweaver Help.

Define a remote server

Dreamweaver site management is based on the principle that your local files are an exact duplicate of your live site on the internet. So, index.html in your check_cs5 folder becomes the front page of your remote site. If you already have a live website that you don’t want to overwrite, use your site’s control panel to create a folder called check_cs5 where you can upload the Check Magazine files.

  1. In Dreamweaver, select Site > Manage Sites.
  2. In the Manage Sites dialog box, select the Check Magazine site.If you did not define the Check Magazine site, create a local folder for the site before you proceed. For more information, see Part 1 of this tutorial series, Setting up your site and project files.
  3. Click Edit.
  4. In the Site Setup dialog box, click Servers to open the panel where you add your server definitions (see Figure 1).

The Servers panel in the Site Setup dialog box.

Figure 1. The Servers panel in the Site Setup dialog box.

Dreamweaver CS5 allows you to set up multiple server definitions for both remote and testing servers. However, only one of each type can be active at any given time.

  1. Click the plus button at the bottom left of the panel to add the remote server definition. This opens a new panel for you to enter the server details (see Figure 2).

The panel where you enter the basic server details.

Figure 2. The panel where you enter the basic server details.

  1. In the Server Name text box, type a name for the server. This is used internally by Dreamweaver to identify the server, so you can choose any name you like. For example, you might want to create a definition for a server where you upload files for a client’s approval, and a different server for the live site. If you have only the one server, call it Remote Server.
  1. From the pop-up menu Connect using, select the method you want to use to connect to the server.The most common methods for connecting to a server on the Internet are FTP and SFTP. If you aren’t sure which to select, ask your hosting company or the server system administrator.
  2. The following options apply to both FTP and SFTP:
    • Enter the server’s FTP address (for example, ftp.yourdomain.com).
    • Enter your user name and password in the appropriate text boxes.
    • Click Test to test your connection.

    If the connection is unsuccessful, verify that you have the correct username and password. Passwords are usually case-sensitive, so make sure that Caps Lock is not turned on. If you selected SFTP, try FTP instead. If that doesn’t solve the problem, consult the troubleshooting section further down this page.

  3. The value that you need to enter in Root Directory is where many people go wrong, and it’s difficult to give precise instructions because hosting companies and server administrators have different policies.As I said earlier, Dreamweaver site management is based on the principle that your local files are an exact duplicate of your live site on the Internet. The value of Root Directory should be the path you need to enter after logging into your server to get to the folder where you want to install index.html.
    • If you want the Check Magazine home page to be the front page of your website, then this needs to be the path to the remote server’s site root. On some servers, it’s public_html. Others might use wwwwwwroot, or even nothing at all. On my remote server, it needs to be /home/username/public_html. If in doubt, ask your hosting company or server administrator.
    • If you want the Check Magazine home page to be in a subfolder called check_cs5, you need to enter the path to that folder. For example, on my server, it would be /home/username/public_html/check_cs5.
  4. The Web URL text box should contain the URL for the folder that you defined as the Root Directory. For example,http://www.example.com/ or http://www.example.com/check_cs5/. Dreamweaver might have tried to guess the correct value, but it’s only a guess. Do not accept the default value without checking it carefully.

Your settings should look similar to Figure 3.

Settings for connecting to a remote server by SFTP.

Figure 3. Settings for connecting to a remote server by SFTP.

  1. Click the Advanced button at the top of the panel to display the advanced options (see Figure 4).

Advanced options for a remote server.

Figure 4. Advanced options for a remote server.

  1. In most circumstances, you should leave these options at their default settings.
    • Maintain synchronization information is selected by default. This keeps track of when the files on your remote server were last updated, and allows you to use the Site Synchronization feature (see Synchronize the files on your local and remote sites in Dreamweaver Help).
    • Automatically upload files to the server on Save should rarely, if ever, be used because it overwrites your live files. If you make a mistake, it’s immediately displayed on your remote site for all the world to see.
    • Enable file check-out is for use in a team environment. It allows only one person at a time to edit a page (seeChecking in and checking out files in Dreamweaver Help).
  2. Click Save to register your server definition. This returns you to the Servers panel of the Site Setup dialog box, where your server definition is now listed (see Figure 5).

The remote server is now registered in the Site Setup dialog box.

Figure 5. The remote server is now registered in the Site Setup dialog box.

Dreamweaver selects the Remote checkbox automatically.

The icons at the bottom of the Servers panel allow you to add another server, or to delete, edit, or make a copy of the selected server definition. Making a copy is useful if you need to change only a few details to connect to a different server.

  1. Click Save to close the Site Setup dialog box, and then click Done to close the Manage Sites dialog box.

Upload your local files

You can now upload your files from your local folder to the remote web server to make your pages publicly accessible.

  1. In the Files panel (Window > Files), select the site’s local root folder (check_cs5).Note: In the Files panel, the local root folder actually begins with “Site – Check Magazine” because that’s the name of the site. If you hover the cursor over that title, Dreamweaver shows you the full path to the check_cs5 folder.
  2. Click the Put Files (up arrow) icon in the Files panel toolbar (see Figure 6).

Put files on the server.

Figure 6. Put files on the server.

  1. When Dreamweaver asks if you want to put the entire site, click OK.Dreamweaver copies all of the files to the remote folder you defined in the previous section. This operation may take some time, as Dreamweaver must connect to the remote server and then upload all the files.

    Note: Normally, you select the local root folder and upload the entire site only the first time you upload. Afterwards, you can upload only the files you’ve changed.

  2. Open your remote site in a browser to make sure all of the files uploaded correctly. Congratulations, you have a site online!

(Optional) Troubleshoot the remote server setup

A web server can be configured in many ways. The following list provides information about some common issues you may encounter in setting up a remote server and how to resolve them:

  • The Dreamweaver FTP implementation may not work properly with certain proxy servers, multilevel firewalls, and other forms of indirect server access.
  • In the panel where you set the basic options for the remote server, set the “Connect using” pop-up menu to FTP, and click the triangle at the bottom of the panel to reveal the More Options section (see Figure 7).

The More Options section can help solve FTP connection problems.

Figure 7. The More Options section can help solve FTP connection problems.

  • Use Passive FTP often solves connection problems caused by a software firewall.
  • Use IPV6 Transfer Mode should be used only if your remote server supports the newer IPv6 protocol (check with your hosting company or server administrator).
  • If you need to connect through a proxy server, select the Use Proxy check box, and click the Preferences link to set up the proxy details.
  • The other two options are self-explanatory.
  • If you still have problems with FTP access, contact your hosting company or system administrator for help.
  • For the Dreamweaver FTP implementation, you must connect to the remote system’s root folder. (In many applications, you can connect to any remote directory, and then navigate through the remote file system to find the directory you want.) Be sure that you indicate the remote system’s root folder (or the check_cs5 subfolder) as the Root Directory. If you have problems connecting, and you’ve specified the host directory using a single slash (/), you might need to specify a relative path from the directory you are connecting to and the remote root folder. For example, if the remote root folder is a higher-level directory, you may need to use ../../ to specify the host directory.
  • File and folder names that contain spaces and special characters often cause problems when transferred to a remote site. Use underscores in place of spaces, and avoid special characters—colons (:), slashes (/), periods (.), and apostrophes (‘) are not permitted in file or folder names.
  • Many servers use symbolic links (Unix), shortcuts (Windows), or aliases (Macintosh) to connect a folder on one part of the server’s disk with another folder elsewhere. For example, the public_html subdirectory of your home directory on the server may really be a link to another part of the server entirely. In most cases, such aliases have no effect on your ability to connect to the appropriate folder or directory; however, if you can connect to one part of the server but not to another, there may be an alias discrepancy.
  • If you encounter an error message such as “cannot put file,” your remote folder may be out of space. For more information, look at the FTP log.

Note: In general, when you encounter a problem with an FTP transfer, examine the FTP log by selecting Site > Advanced > FTP Log. For more information, see the extensive tech note on FTP troubleshooting on the Adobe website.

Adobe Dreamweaver CS5 – Part 5: Adding the Spry menu


Adobe Dreamweaver CS4 logo

Image via Wikipedia

Welcome to Part 5 of this tutorial series on creating your first website. This tutorial shows you how to add a Spry Menu Bar widget to the index page for Check Magazine, a fictional publication. A Spry Menu Bar widget is a set of navigational menu buttons that link to other pages of your website. In many cases, the menu displays submenus when a site visitor hovers over one of the buttons (though you won’t be using submenus in this tutorial). You may have heard of a navigation bar for a website—that’s essentially what I’m talking about here. Adobe calls its navigation bar a Spry Menu Bar widget, because the widget is a built-in part of the Adobe Spry framework for Ajax and comes installed with Dreamweaver CS3 and later.

The tutorial also shows you how to customize the widget by editing its CSS rules.

Note: For more information about the Spry Menu Bar widget in general, see Working with the Menu Bar widget in Dreamweaver Help. For more information about the Spry framework for Ajax, see About the Spry framework in Dreamweaver Help.

Locate your files and review your task

In this tutorial, you’ll begin with the index page you added text to in Part 4, Adding the main image text. If you did not complete that tutorial, you must complete it before proceeding, or download first_website_pt4_completed.zip and begin with those files. If you haven’t completed Part 1: Setting up your site and project files, you will need to complete that tutorial as well.

Your task in this tutorial is to add a Spry Menu Bar widget to the banner area of the Check Magazine home page. You’ll also learn how to customize the menu bar by editing its CSS rules. Figure 1 shows what the banner area will look like in a browser after you’ve added the menu bar.

The banner area of the Check Magazine home page with a Spry Menu Bar widget included.

Figure 1. The banner area of the Check Magazine home page with a Spry Menu Bar widget included.

Basically what you’ll do to accomplish this task is very similar to what you did in Part 4, Adding the main image text, of this tutorial series. You’ll add another content element to an already specified div (in this case, the new content element is a Spry Menu Bar widget, and the already specified div is the banner div), and use a combination of relative and absolute positioning to move the new element into place.

Insert and position the Spry Menu Bar widget

Dreamweaver lets you insert two kinds of Menu Bar widgets: vertical and horizontal. In this tutorial, you’ll insert a horizontal Menu Bar widget, as pictured in the previous section.

  1. In Dreamweaver, open the index.html file that you created in Part 4: Adding the main image text.
  2. Click in the banner div to select the banner image. Then press your right arrow key once to place the Insertion point to the right of the image, but still inside the div. You should see a large blinking Insertion point in the banner div (the top div.
  3. Click the Split view button to make sure the Insertion point is in the banner div between the <img> tag and the closing </div> tag. (This is very important; see Figure 2).

The Insertion point inside the banner div.

Figure 2. The Insertion point inside the banner div.

  1. Select Insert > Spry > Spry Menu Bar.Tip: You can also insert a Spry Menu Bar widget from the Spry category of the Insert panel. The Spry category of the Insert panel shows you all of the Spry widgets available in Dreamweaver.
  2. In the Spry Menu Bar dialog box, leave Horizontal selected and click OK.The Menu Bar widget, with its default color scheme of black text and gray background, is inserted in the page, but pushes the main image to the right (see Figure 3).

The Spry Menu Bar widget drops below the banner image, and displaces the main image.

Figure 3. The Spry Menu Bar widget drops below the banner image, and displaces the main image.

  1. You’ll fix the layout in a moment, but take a look at the code for the Menu Bar widget in Code view. The Menu Bar widget is actually a set of unordered lists nested inside a container <ul> (unordered list) tag. Each menu item is in<li> (list item) tags, and everything is styled with CSS. The container <ul> tag is assigned the CSS class attributeMenuBarHorizontal , the main attribute referenced in the many CSS rules responsible for the widget’s formatting.Note: I have not talked about CSS class rules in this series, and I’m not going to go into an in-depth explanation of them here; but essentially a class rule is a type of CSS rule that lets you format any HTML element on the page. Class rules do not restrict you to formatting specific tags or elements with IDs. For more information on class rules, see Understanding Class Rules in Dreamweaver
  2. The first thing you should do after inserting a Spry widget is to save the page.The Copy Dependent Files dialog box appears, stating that Dreamweaver is copying a number of supporting files to your local site. These files are all related to the display and functionality of the Spry Menu Bar widget. In particular, the SpryMenuBar.js file contains all of the information that drives the widget’s functionality, whereas the SpryMenuBarHorizontal.css file contains all of the CSS rules that dictate the widget’s formatting.
  3. Click OK to close the Copy Dependent Files dialog box and install the dependent files.Dreamweaver adds a SpryAssets folder to the root folder of your site. (You might need to click the Refresh button in the Files panel to see the new SpryAssets folder.) This folder contains all of the files necessary for the Spry Menu Bar widget to function. Later, you’ll need to make sure you upload these files to the web server when you publish your page on the Web.You’ll also notice that the Related Files toolbar now lists the Spry files associated with the index page. That’s because when you saved the page after creating the widget, Dreamweaver automatically attached the required files to the page for you.
  4. Now, let’s fix the layout.To position the Spry Menu Bar correctly, you need to create a rule for the banner div. It’s generally a good idea to keep your style sheet in logical order, so the new rule should come after the body rule. Dreamweaver always inserts a new CSS rule immediately after the rule that’s currently selected in the CSS Styles panel.Open the CSS Styles panel, and make sure it’s in All mode. Select the #container rule, and click the New CSS Rule button (see Figure 4).

Select the #container rule and click the New CSS Rule button.

Figure 4. Select the #container rule and click the New CSS Rule button.

  1. Use the following settings in the New CSS Rule dialog box:
    • Set the Selector Type pop-up menu to ID.
    • Type #banner in the Selector Name text box.
    • Make sure the Rule Definition pop-up menu is set to check_cs5.css.
  2. Click OK to open the CSS Rule Definition dialog box, and select Positioning from the Category list on the left.
  3. Select relative from the Position pop-up menu, and click OK to close the dialog box.
  4. The main image snaps back into position, with the menu bar occupying a block of its own between the banner and main images (see Figure 5).

The menu now occupies a block of its own between the two images.

Figure 5. The menu now occupies a block of its own between the two images.

  1. Move your cursor pointer over the menu bar. This triggers the display of a turquoise tab at the top left. Click this tab to select the menu bar (see Figure 6).

Click the turquoise tab to select the menu bar.

Figure 6. Click the turquoise tab to select the menu bar.

  1. In the Property inspector, change the menu’s ID (in the text box just below Menu Bar) from the default MenuBar1to check_menu, and press Tab to make the change. The new ID is displayed in the Property inspector and in the Tag selector at the bottom of the Document window (see Figure 7).

Change the menu bar's ID in the Property inspector.

Figure 7. Change the menu bar’s ID in the Property inspector.

  1. You can now create a new CSS rule to position the menu bar.With the menu bar still selected in Design view, open the CSS Styles panel, select #banner , and click the New CSS Rule button.
  2. In the New CSS Rule dialog box, the Selector Name text box should be automatically populated with#container #banner #check_menu .Click the Less Specific button twice to leave just #check_menu .Make sure that Rule Definition is set to check_cs5.css, and click OK.Note: If the correct values weren’t automatically selected in the New CSS Rule dialog box, just set them manually. When setting the values manually, select ID from the Selector Type pop-up menu.
  3. In the CSS Rule Definition dialog box, select Positioning from the Category list on the left.
  4. In the Positioning category, use the following settings:
    • Position: absolute
    • Top: 50 px
    • Right: 0 px
    • Bottom: 0px

    Click OK to close the dialog box.

  5. Check the position of the menu bar in Design view. It’s not quite right. It’s aligned with the right edge of the banner image, but isn’t aligned correctly at the bottom (see Figure 8).

The menu bar isn't in the right position in Design view.

Figure 8. The menu bar isn’t in the right position in Design view.

The reason for this is because there are conflicting top and bottom offsets for the #check_menu style rule. The ultimate aim is to align the bottom and right of the menu bar with the bottom and right edges of the banner image, in the same way as you aligned the main_text div against the guides in part 4 of this tutorial series.

Unfortunately, the menu’s own style rules prevent Design view from displaying the menu in the correct position. So, the top offset of 50 pixels has been added as a temporary measure to make life easier while working in Design view.

  1. Select #check_menu in the CSS Styles panel, and move your cursor pointer to the left of the top property in the Properties pane until the Disable CSS Property icon appears (see Figure 9).

Temporarily disable the top property for #check_menu.

Figure 9. Temporarily disable the top property for #check_menu.

Click once to disable the top property temporarily. If you’re lucky, the menu should snap into its correct position, but it’s more likely to jump to the top of the banner div and remain inaccessible in Design view.

Note: If you’re using an older version of Dreamweaver, you’ll need to comment out the top property manually in the style sheet.

  1. Click the Live View button. The menu is displayed where you want it—aligned with the right and bottom edges of the banner image (see Figure 10).

The menu bar is in the right position in Live View.

Figure 10. The menu bar is in the right position in Live View.

  1. Click the Live View button to exit Live View, and re-enable the top property by clicking the disabled symbol to the left of its name in the CSS Styles panel.
  2. Select File > Save All Related Files to save all your changes.

Change the width of the Menu Bar widget

The appearance of the Spry Menu Bar widget is controlled by the CSS in the SpryMenuBarHorizontal.css file that Dreamweaver just added to your site. The SpryMenuBarHorizontal.css file resides in the SpryAssets folder (see Figure 11).

The SpryMenuBarHorizontal.css file in the SpryAssets folder of your site.

Figure 11. The SpryMenuBarHorizontal.css file in the SpryAssets folder of your site.

You can (and now do) have multiple CSS files attached to a single page. For example, if you add more Spry widgets to the page, Dreamweaver creates and attaches a new style sheet for each of the new widgets you add.

  1. Double-click SpryMenuBarHorizontal.css in the Files panel to open it in the Document window. You’ll see that the CSS rules that format the Menu Bar widget are long and—if you’re not familiar with CSS—confusing. Unfortunately, of all the Spry widgets that come with Dreamweaver, the Menu Bar widget is the most complicated animal, and in order to avoid confusing you any more than you need to be, I’m going to avoid talking in depth about these rules.Note: There’s an in-depth tutorial about customizing a Spry menu bar on my website athttp://foundationphp.com/tutorials/sprymenu/customize1.php.Luckily, Dreamweaver makes it somewhat easier to customize the Menu Bar widget by giving you the ability to edit the widget’s CSS rules in the CSS Styles panel.
  2. Any changes made to SpryMenuBarHorizontal.css automatically affect every Spry menu bar in the same site. So, before editing the style sheet, it’s a good idea to make a copy, and make the changes to the copy. That way, if you make a mess of the menu, you can always revert to the original file.With SpryMenuBarHorizontal.css the active document, select File > Save As. In the Save As dialog box, navigate to the styles folder in the Check Magazine site, and save the file as check_menu.css. When Dreamweaver asks if you want to update the links, click Yes.
  3. Close both SpryMenuBarHorizontal.css and check_menu.css.
  4. You need to detach SpryMenuBarHorizontal.css from index.html and attach check_menu.css in its place.In the CSS Styles panel, select SpryMenuBarHorizontal.css, and click the trash can button at the bottom of the panel to unlink the style sheet (see Figure 12).

Unlink SpryMenuBarHorizontal.css.

Figure 12. Unlink SpryMenuBarHorizontal.css.

  1. Click the button that looks like a chain link at the bottom of the CSS Styles panel to attach a new style sheet (see Figure 13).

Attach a new style sheet.

Figure 13. Attach a new style sheet.

  1. In the Attach External Style Sheet dialog box, click the Browse button to navigate to check_menu.css in the stylesfolder, and click OK (Windows) or Choose (Mac OS X) to select it. Then click OK to close the Attach External Style Sheet dialog box.You should now have two style sheets listed in the CSS Styles panel: check_cs5.css and check_menu.css (see Figure 14).

The copy of the menu's style sheet has been attached to the page.

Figure 14. The copy of the menu’s style sheet has been attached to the page.

  1. Save index.html. The two style sheets should be listed in the Related Files toolbar, together with SpryMenuBar.js, the external JavaScript file that controls the menu (see Figure 15).

The two style sheets and the JavaScript file are listed in the Related Files toolbar.

Figure 15. The two style sheets and the JavaScript file are listed in the Related Files toolbar.

  1. Click the Current button in the CSS Styles panel. (You’ve been working in All mode up until now.)
  2. In the Document window, select the Menu Bar widget by clicking its turquoise tab. (Hover over any part of the widget to make the tab appear.)Tip: You can always tell which page element is selected by looking at the Property inspector (Window > Properties). In this case, you’ll be able to tell if the Spry Menu Bar widget is selected if you see its properties displayed in the Property inspector.You’ll notice a few things happening in the CSS Styles panel after you’ve selected the widget. One is that the#check_menu rule appears in the Properties pane of the CSS panel. That’s because the #check_menu rule governs the <ul> container for the widget (the tag you’ve selected). The other thing you’ll notice is the appearance of properties for the #check_menu rule in the Properties pane. Even with a large monitor, you’ll probably need to resize the CSS Styles panel to see everything I’m talking about. You can resize the panel by dragging the bottom boundary of it downwards. This will reduce the height of the Files panel, but that’s OK. Alternatively, double-click the Files panel tab to close it. For now, you need as much real estate in the CSS Styles panel as possible (see Figure 16).

The CSS Styles panel in Current mode.

Figure 16. The CSS Styles panel in Current mode.

Tip: You can also resize any of the three separate panes in the CSS Styles panel by dragging their top or bottom borders.

OK, now that you can see everything you need to see in the CSS Styles panel, you can begin editing the widget. But before you proceed, ensure that the Rules pane in the CSS Styles panel looks like Figure 16. THIS IS VERY IMPORTANT. If it doesn’t, chances are you have About view showing in the Rules pane, rather than the cascade of rules. If you have About view showing in the Rules pane, click the Cascade button in the upper right corner of the Rules pane. (There are only two buttons there; it’s the one on the right.)

  1. Click the ul.MenuBarHorizontal rule in the Rules pane to select it. When the ul.MenuBarHorizontal rule is selected, the full name of the rule appears below in the title bar of the Properties pane.
  2. Click the Add Property link in the Properties pane. This opens a pop-up menu.
  3. Click the pop-up menu arrow to reveal the menu, scroll down to find the text-transform property, and select it.
  4. From the value pop-up menu to the right, select uppercase.The text in your Menu Bar widget changes to uppercase.
  5. Now click inside the text ITEM 2 in the Menu Bar widget. (Do not select the text, simply click somewhere inside of it.)Three more rules appear in the Rules pane of the CSS Styles panel, with the last rule selected. There are now a total of eight rules listed, five of them related to the Menu Bar. (You might need to expand the Rules pane to see them all.)
  6. In the Rules pane, click the third Menu Bar rule in the list, the ul.MenuBarHorizontal li rule.
  7. In the Properties pane, edit the last property listed ( width ). Click the 8 em value of the width property to make it editable, and then change the width to 7 em (see Figure 17), and then press Enter/Return.

Change the width property for the ul.MenuBarHorizontal li rule.

Figure 17. Change the width property for the ul.MenuBarHorizontal li rule.

The width of the menu items in the menu bar is reduced to 7 em. Don’t worry that the menu is no longer aligned with the right edge of the banner image. You’ll fix that in a moment.

Note: When you see strikethrough lines in the CSS Styles panel (for example, the width property is struck through in Figure 17) it means the property doesn’t directly affect what’s currently selected in Design or Code view. Your cursor is inside the text, but the width property here governs the surrounding <li> tags, not the text itself. Of course, changing the width property of the <li> element has an indirect effect on the text inside.

If you want to see what I mean, hover over the edge of the ITEM 2 menu item in Design view until you see its border outlined in red, then click to select the item. When you select the item, all strikethroughs in the CSS panel should disappear. That’s because all of the rules you’re now viewing directly affect that selection (the <li> tag). And if you’re still not convinced, just look down at the Tag Selector at the bottom of the Document window. The <li> tag should be selected down there as well.

If you do all of this, be sure to click back inside the ITEM 2 text when you’re finished. You need to have the <li> tag deselected for the rest of the following tasks.

  1. In the Rules pane, click the fourth Menu Bar rule in the list, the ul.MenuBarHorizontal a rule.
  2. In the Properties pane, select the padding property and click the Delete CSS Property button, the trash can icon (see Figure 18).

Delete the padding property from the ul.MenuBarHorizontal a rule.

Figure 18. Delete the padding property from the ul.MenuBarHorizontal a rule.

After you delete this rule, the Menu Bar should be much shorter in Design view. It also springs back in alignment with the right edge of the banner image.

Edit the Menu Bar widget’s text and links

Now that you’ve reduced the default size of the menu bar, you’ll edit the menu bar items themselves. But before you do that, I want to show you how the default submenus of the Menu Bar widget work.

  1. Click the Live View button to enter Live View.
  2. Run the cursor over the menu bar and observe the interaction. Items 1 and 3 have submenus. If you hover over Item 3, you’ll see that the Item 3.1 submenu has a submenu (see Figure 19).

The Menu Bar widget and its submenus.

Figure 19. The Menu Bar widget and its submenus.

Menu Bar widgets can have as many submenus as you want. However, the Dreamweaver Property inspector only supports two levels of submenus. To add more submenus, you need to work directly in the code.

You don’t need to worry about submenus right now though. You’re actually going to get rid of all of them for this website.

  1. Click the Live View button again to exit Live View.
  2. Select the Menu Bar widget in the Document window by clicking its turquoise tab.
  3. In the Property inspector, make sure Item 1 is selected in the first column.
  4. Select the submenu item, Item 1.1, in the second column, and click the minus (Remove menu item) button (see Figure 20).

Delete the first submenu item from Item 1.

Figure 20. Delete the first submenu item from Item 1.

  1. Delete Item 1.2 and Item 1.3 as well.
  2. Select Item 3 in the first column.
  3. Select the submenu item, Item 3.1, in the second column, and click the minus (Remove menu item) button.When you try to delete this submenu, Dreamweaver alerts you that you are also deleting the submenu’s submenu (referred to as its children). Click OK.
  4. Delete Item 3.2 and Item 3.3 as well.Now that you’ve deleted all of the submenus, you are ready to edit the menu bar text.
  5. Select Item 1 in the first column again and then do the following:
    • In the Text text box, type Features.
    • In the Link text box, type news.html (see Figure 21).

Text and Link values added for Item 1 of the Menu Bar widget.

Figure 21. Text and Link values added for Item 1 of the Menu Bar widget.

Note that the Menu Bar widget is changing before your very eyes. You don’t need to type capital letters in the Property inspector because you already defined a CSS rule that makes all letters in the Menu Bar widget capital no matter what.

Additionally, as in an earlier tutorial, you’re going to use the news.html page as your sample page for all links. But if you were building the website for real, you would be linking to separate pages.

  1. Select Item 2 in the first column of the Property inspector and then do the following:
    • In the Text text box, type Fashion.
    • In the Link text box, type news.html.
  2. Select Item 3 in the first column of the Property inspector and then do the following:
    • In the Text text box, type Lifestyle.
    • In the Link text box, type news.html.
  3. Select Item 4 in the first column of the Property inspector and then do the following:
    • In the Text text box, type Calendar.
    • In the Link text box, type news.html.

    Your Menu Bar widget now looks like Figure 22.

The Menu Bar widget after the text for all menu items has been changed.

Figure 22. The Menu Bar widget after the text for all menu items has been changed.

You’re almost there. You just need to add one more menu item to the widget.

  1. With the Menu Bar widget still selected, click the plus button above the first column in the Property inspector (see Figure 23).

Add another menu item.

Figure 23. Add another menu item.

Dreamweaver adds an Untitled Item to the menu bar.

  1. With the Untitled Item selected in the first column of the Property inspector, do the following:
    • In the Text text box, type News.
    • In the Link text box, type news.html.
  2. Click anywhere on the page to deselect the menu bar. Don’t worry if the new item in the menu bar has dropped down below the other items.
  3. Select File > Save All Related Files.
  4. Click the Live View button to turn on Live View. Then click it again to exit Live View. The menu items should all line up in a single row.

Change the Menu Bar widget’s colors

Only a few more edits and the menu bar will be final.

  1. Click anywhere inside the Menu Bar widget. For example, click inside the word Fashion.The five Menu Bar–related rules appear in the Rules pane of the CSS Styles panel.
  2. Click the fourth Menu Bar–related rule, the ul.MenuBarHorizontal a rule.
  3. In the Properties pane, click the black box in the color value field and use the eyedropper to select white ( #FFF), as shown in Figure 24.

Change the default text color.

Figure 24. Change the default text color.

You’ll notice that the text of the Menu Bar widget has changed to white. The ul.MenuBarHorizontal a rule is the rule that controls the text color of the menu items in their default state (that is, when you’re not hovering over them).

  1. Click the gray box in the background-color value field and use the eyedropper to select black ( #000 ).The background color of the menu items changes to black.
  2. Click the Live View button and run your cursor over the menu items.Yikes! You’re getting blue backgrounds upon hovering. That’s another default property of the Spry Menu Bar widget, so let’s change it.
  3. Click the Live View button again to exit Live View.
  4. Click anywhere inside the Menu Bar widget. For example, click inside the word Fashion.
  5. The five Menu Bar–related rules appear in the Rules pane again.Click the last Menu Bar–related rule, the ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus rule.Note: I know that it’s impossible to see the full name of this rule in the Properties pane. You just have to trust me that it’s the final rule listed in the Rules pane.
  6. In the Properties pane, click the blue box in the background-color value field and use the eyedropper to select black ( #000 ).
  7. Click the #FFF default color in the color value field, change it to #00ADEF (that’s zero, zero, A, …) and press Enter/Return (see Figure 25).

Change the background and text properties for the ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus rule.

Figure 25. Change the background and text properties for the ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus rule.

The #00ADEF color is blue, as you can see. It’s the color the menu bar’s text will change to when you hover over the links in the menu bar.

Note: Don’t forget the hash sign at the beginning of the hexadecimal number for the color.

  1. There’s one more rule you need to edit before you’re finished; it’s a tricky one, hidden deep within the CSS file. You’ll switch to All mode in the CSS Styles panel in order to make it easier to find and edit the rule.In the CSS Styles panel, click the All button to view All mode.As you know from previous tutorials, All mode shows you all of the rules that affect the page you’re working on, not just the rules that affect the current selection.
  2. Click the plus sign next to check_menu.css to expand the list of rules if it isn’t already expanded. (Macintosh users need to click the arrow to expand the list.)The check_menu.css file name is at the bottom of the All Rules pane, so you might need to scroll or resize the pane to see it.
  3. Scroll down and locate the rule that begins ul.MenuBarHorizontal a.MenuBarItemHover . . . (The rule is so long I don’t even want to spell the whole thing out.) It’s immediately below the ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus rule that you were just editing in Current mode (see Figure 26).

Select the world's longest CSS rule.

Figure 26. Select the world’s longest CSS rule.

Once you’ve located the rule, click it to select it.

You now need to do exactly the same thing that you did for the ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus rule. Sorry, but it’s just the way the CSS for the Menu Bar widget is written, and if you don’t change this rule, too, the hover states will not work as you intend them to work.

  1. In the Properties pane, click the blue box in the background-color value field and use the eyedropper to select black ( #000 ).
  2. Click the #FFF default color in the color value field, change it to #00ADEF (that’s zero, zero, A, …), and press Enter/Return.Note that nothing has happened in Design view for awhile. Why? Because you’ve only been editing properties that affect the hover and focus states of the menu bar. To see those states, you need to enter Live View and test the widget again.But first, you need to save the CSS file so that the changes can take effect.
  3. Select File > Save All Related Files.
  4. Click the Live View button, and hover over the items in your menu bar.
  5. The menu is still in the wrong place, so select the #check_menu style rule in the CSS Styles panel (it’s in check_cs5.css), and click to the left of the top property to disable it. The menu drops into place. The hover background color is now black, and the hover text color is the blue you defined (see Figure 1).
  6. Hold down the Ctrl key (Windows) or the Cmd key (Mac OS X), and click one of the links. The news.html page loads into Live View.

The menu loads news.html into Live View.

Figure 27. The menu loads news.html into Live View.

  1. The menu in news.html is only an image, so click the Home or Back button on the Browser Navigation bar to return to index.html.Note: Live View navigation works only in Dreamweaver CS5. If you are using an older version of Dreamweaver, you need to test the links by previewing the index page in an ordinary browser.
  2. Click the Live View button to exit Live View. The menu moves back to the top of the banner image. If you want to do any further work on it, re-enable the top property for the #check_menu style rule. However, the top property should remain commented out when the page is uploaded to a remote server.

It’s unfortunate that Design view can’t handle the position of the menu accurately, but that’s what Live View is for—to test the way the page will look in a standards-compliant browser. Design view should only ever be taken as an approximation, although most of the time, it’s a very close one.

Add a top-level heading to the page

There’s just one final tweak that you need to make to index.html before it’s complete. The page doesn’t have a top-level heading ( <h1> ). The design uses the banner image instead. This looks fine in a browser, but search engines and screen readers expect pages to be organized with a proper hierarchy of headings: <h1> at the top of the page, <h2>for sideheads, and <h3> for subsections. You rarely need to use deeper levels of headings, and you should never choose a particular level just because of its default size. As you have seen throughout this tutorial series, you can use CSS to change the default look of a tag.

The problem with adding an <h1> tag to this page is that it will destroy the design. Well, it would if it weren’t for the magic of CSS. You can use absolute positioning to move the heading out of view. People visiting the site in a visual browser see the banner as normal, but search engines, text browsers, and screen readers see the <h1> at the start of the page.

Here’s how you do it.

  1. You need to add the <h1> tag between the opening <div> tags of the container and banner divs. The obvious way of doing this is to switch to Code view, and add it manually. However, I’d like to show you a neat trick to get the insertion point in the right place.Click anywhere inside the banner at the top of the page. Then select <div#banner> in the Tag selector at the bottom of the Document window. This selects the whole div.
  2. Press the left arrow key once. If you check in Split view, you’ll see that the insertion point is to the left of the opening tag of the banner div.
  3. In the Property inspector, make sure the HTML button is selected, and choose Heading 1 from the Format pop-up menu. This inserts a pair of <h1> tags between the two <div> tags, and opens up a large blank space above the banner image.
  4. In Design view, click in the space that has just opened up, and type Check Magazine: Fashion and Lifestyle (see Figure 28).

Adding a top-level heading to the page.

Figure 28. Adding a top-level heading to the page.

  1. Open the CSS Styles panel, which should still be in All mode, and scroll up to the #container rule in check_cs5.css. Select it, and click the New CSS Rule button at the bottom right of the CSS Styles panel.
  2. If your insertion point is still inside the heading, the New CSS Rule dialog box should already have the correct settings. Check that they look like Figure 29, and amend them if necessary.

Creating a new CSS rule for the top-level heading.

Figure 29. Creating a new CSS rule for the top-level heading.

Note: The value in the Selector Name text box is #container h1 . This is a descendant selector that affects <h1>tags in the container div. Normally, a page should have only one <h1> tag, so you could use h1 on its own. However, the selection made by Dreamweaver is fine.

  1. Click OK to open the CSS Rule Definition dialog box, and select the Positioning category.
  2. Select absolute from the Position pop-up menu.
  3. In the Top text box, type -500 (minus 500), and set the pop-up menu alongside to px.
  4. Click OK to close the CSS Rule Definition dialog box, and select File > Save All Related Files.
  5. Test the page in Live View, and BrowserLab. The top-level heading is tucked out of sight, 500 pixels above the container div. You can’t see it, but search engines, text browsers, and screen readers can.

Congratulations! You’ve finished the index.html page for Check Magazine, and the client is very pleased. If you want to compare your work against the completed files for the series, download the first_website_pt5_completed ZIP file.

The last thing you need to do is publish the page and its assets to a web server so that other people can view your work. I’ll show you how to do that in the next tutorial, Part 6: Publishing your website

Adobe Dreamweaver CS5 – Part 3: Adding content to pages


Adobe Dreamweaver CS4 logo

Image via Wikipedia

Requirements

Welcome to the third part of this tutorial series on creating your first website. This tutorial shows you how to add content to web pages in Adobe Dreamweaver CS5/CS5.5. You can add many different kinds of content to web pages, including graphics, text, links, and Spry widgets—to name just a few. After you’ve added content to your pages, you can preview your work in Dreamweaver so that you can see what it will look like on the web.

Note: You won’t be adding a Spry widget to the page until Part 5 of this tutorial series, Adding the Spry menu.

Locate your files and review your task

In this tutorial, you’ll begin with the CSS layout (index.html) you created in Part 2, Creating the page layout. If you did not complete that tutorial, you must complete it before proceeding, or download first_website_pt2_completed.zip(475 KB) and begin with those. All the required assets for this tutorial are in the check_cs5 local site folder that you set up in Part 1. If you are using the completed files from Part 2, follow the instructions in Part 1 for setting up the Check Magazine site on your local computer.

Your task is to add assets to the home page for Check Magazine, a fictional publication. You’ll learn how to add images, text, and links. You’ll also learn how to format text using CSS. Figure 1 shows what the finished page will look like at the end of Part 3.

The page after you have entered content into it.

Figure 1. The page after you have entered content into it.

Insert images

After you create your page layout, you are ready to add assets to the page, starting with images. You can use several methods to add images to a web page in Dreamweaver. In this section, you’ll add three images to the Check Magazine page using various methods.

Insert an image by using the Insert menu

In Part 2, you used the Insert panel to insert an image. This time, you’ll use the Insert menu.

  1. In Dreamweaver, open the index.html file that you created in Part 2, Creating the page layout.
  2. Delete the placeholder text in the left_column div. Make sure the Insertion point remains inside the div (see Figure 2). (In other words, make sure you don’t click anywhere outside the div after you’ve deleted the placeholder text.)

The left_column div with the placeholder text deleted.

Figure 2. The left_column div with the placeholder text deleted.

  1. Press Enter (Windows) or Return (Mac OS X) once to create more space in the div.
  2. Press the up arrow on your keyboard to move the Insertion point back up to the top of the div, and click the Split button to see what has happened in the underlying code. Dreamweaver has inserted two paragraphs ( <p> tags), each with &nbsp; inside them (see Figure 3).

Dreamweaver has inserted two empty paragraphs in the div.

Figure 3. Dreamweaver has inserted two empty paragraphs in the div.

Note: The &nbsp; is the HTML entity (code that represents a special character) for a nonbreaking space. It’s there to make the paragraph easier to select in Design view. Dreamweaver normally deletes it automatically as soon as you start typing or insert anything into the paragraph.

  1. Select Insert > Image.
  2. In the Select Image Source dialog box, navigate to the site’s images folder, select the car.jpg file, and click OK (Windows) or Choose (Mac OS X).
  3. Dreamweaver displays the Image Tag Accessibility Attributes dialog box (unless you’ve changed the default preferences).Type Car in the Alternate Text text box and click OK.The image appears in Design view, and Dreamweaver inserts the necessary HTML in the underlying code, removing the nonbreaking space in the process (see Figure 4).

The inserted car image and the underlying code.

Figure 4. The inserted car image and the underlying code.

  1. Leave the image selected (in other words, don’t click anywhere else on the page), and look at the Property inspector at the bottom of the Dreamweaver application window. (If the Property inspector is hidden, you can display it by selecting Window > Properties).

The Property inspector displays all of the properties for whatever asset you have selected in the Document window. Since we have our new image selected, the Property inspector is displaying the properties for the car.jpg image. You can see that the Property inspector displays the width and height of the image, the file path to the image, and the alternate text that you specified before inserting the image (see Figure 5).

The Property inspector displaying image properties.

Figure 5. The Property inspector displaying image properties.

The Property inspector is one of the most powerful tools in Dreamweaver. You can use it to change properties for any selected asset on your page at any time.

Note also that the <img> tag is selected in the Tag selector (at the bottom of the Document window)—yet another way that Dreamweaver communicates the precise selection of page assets.

Now let’s add the remaining images.

Insert an image by dragging

To insert an image by dragging:

  1. Delete the placeholder text in the center_column div. Make sure the Insertion point remains inside the div.
  2. Press Enter (Windows) or Return (Mac OS X) once to create more space in the div.
  3. Press the up arrow on your keyboard to move the Insertion point back up to the top of the div.
  4. In the Files panel (Window > Files), locate the data_addict.jpg file (it’s inside the images folder) and drag it to the insertion point in the center_column div (see Figure 6).Important: Make sure you drag the data_addict.jpg to the Insertion point at the top of the center_column div. It’s easy to mistakenly drop the image in the lower half of the div when dragging.

Drag the data_addict.jpg file to the insertion point in the center_column div.

Figure 6. Drag the data_addict.jpg file to the insertion point in the center_column div.

  1. In the Image Tag Accessibility Attributes dialog box, type Data in the Alternate Text text box and click OK.The image appears on your page. You can see all of its properties in the Property inspector.
  2. Save the page. It’s important to save often!

Insert an image from the Assets panel

To insert an image from the Assets panel:

  1. Delete the placeholder text in the right_column div. Make sure the Insertion point remains inside the div.
  2. Press Enter (Windows) or Return (Mac OS X) once to create more space in the div tag.
  3. Press the up arrow on your keyboard to move the Insertion point back up to the top of the div.
  4. Click the Assets tab in the Files panel group, or select Window > Assets to make your site assets appear.The images category in the Assets panel is selected by default. If it isn’t selected, click the Images button to view your image assets (see Figure 7).

The Images category of the Assets panel.

Figure 7. The Images category of the Assets panel.

The Assets panel displays assets for the site associated with the active document in the Document window. In the screen shot, you can see that the Assets panel displays the selected image asset in the preview area.

  1. In the Assets panel, select the helmet.jpg file.
  2. Do one of the following to insert the helmet.jpg file in the page:
    • Drag the helmet.jpg file to the insertion point in the right_column div.
    • Click Insert at the bottom of the Assets panel.
  3. In the Image Tag Accessibility Attributes dialog box, type Helmet in the Alternate Text text box and click OK.
  4. Save the page, which should now look as shown in Figure 8.

The page after inserting images in the columns.

Figure 8. The page after inserting images in the columns.

For more information on working with the Assets panel, see Working with Assets in Dreamweaver Help.

Insert text

Now you’ll add text to the page. You can type text directly in the Document window or you can copy and paste text from other sources (such as Microsoft Word or plain text files). Later, you’ll use CSS to format the text.

  1. Return to the Files panel by clicking its tab.
  2. In the Files panel, locate the text.txt file (in the check_cs5 root folder) and double-click the file’s icon to open it in Dreamweaver.You’ll notice that this window is in Code view (see Figure 9) and cannot be switched to Design view because it’s not an HTML file.

The text file opens in Code view only.

Figure 9. The text file opens in Code view only.

  1. In the text.txt Document window, select the first block of text (beginning with “Inside Tesla Motors®” up to and including “read more…”).
  2. Copy the text by pressing Ctrl+C/Cmd+C, or by selecting Edit > Copy. Alternatively, you can right-click and select Copy from the context menu that appears.
  3. Leaving the text.txt file open, click the tab of the index.html document.
  4. Click inside the left_column div below the car image, placing the Insertion point in the same place where you created space earlier (see Figure 10).

The Insertion point placed below the car image in the left_column div.

Figure 10. The Insertion point placed below the car image in the left_column div.

  1. Paste the text by pressing Ctrl+V/Cmd+V, or by selecting Edit > Paste. Alternatively, right-click and choose Paste from the context menu that appears.

The text is displayed in the div (see Figure 11).

The Inside Tesla Motors® text pasted in the div.

Figure 11. The Inside Tesla Motors® text pasted in the div.

Don’t worry about the look of the text. You’ll format it with CSS so that it looks more like the text in our design comp.

  1. Return to the text.txt file by clicking its tab.
  2. In the text.txt Document window, select the second block of text (beginning with “Facts and Figures” up to and including “read more…”).
  3. Copy the text.
  4. Leaving the text.txt file open, click the tab of index.html.
  5. Click inside the center_column div below the data image, placing the Insertion point in the same place where you created space earlier.
  6. Paste the text.
  7. And one last time, return to the text.txt file by clicking its tab.
  8. In the text.txt Document window, select the third block of text (beginning with “Today’s Self Improvement” up to and including “read more…”).
  9. Copy the text.
  10. Close the text.txt file by clicking the X in the upper-right corner of its tab. (You won’t need the remaining text until later.)
  11. On the index.html page, click inside the right_column div below the helmet image, placing the Insertion point in the same place where you created space earlier.
  12. Paste the text.Your three columns are now filled with text (see Figure 12).

The text in all three columns.

Figure 12. The text in all three columns.

  1. Save the index.html page.

Now all you need to do is format the text so that it looks more like what the designer intended.

Format text with CSS

In Part 2, Creating the page layout, you learned how to insert div tags and then position those tags on the page to create the layout. You separated content (the HTML div tags) from presentation (the CSS that controls the layout) by creating new CSS rules, placing them in an external style sheet, and then applying them to the div tags on your page. In a nutshell, you learned that you can insert elements on a page and create styling rules in a linked CSS page, and that when you apply those styling rules to particular elements on a page, those elements are directly affected by the rules.

Well, the same holds for text on a page. CSS is used to format text as much as it is to position div tags. You type or paste your text on the page, create a CSS rule, and then apply the rule to the text, just as you would apply it to a div. In fact, all text is contained within some sort of tag—it might be a div, but it could also be a paragraph tag ( <p> ), a heading tag ( <h1> , <h2> , etc) or any other kind of tag. Normally what you do when you format text with CSS is apply the CSS rule to the particular tag that you want to format.

Before going on, I recommend that you read Understanding Cascading Style Sheets, a basic overview of how CSS works to format text. Having a little background information about the ins and outs of CSS will make the rest of this tutorial a lot easier to comprehend.

Now let’s format some text.

  1. Open the CSS Styles panel (Window > CSS) by clicking its tab.
  2. (Optional) If it’s not already closed, double-click the Insert panel to close it and create more room.
  3. In the CSS Styles panel, click the All button to make sure you are viewing All mode.Earlier, when you first used the CSS Styles panel to create a new rule, the panel displayed no rules because you hadn’t created any yet. Now that you have a bunch of rules applied to elements on the page, the CSS panel is displaying all of the pertinent rules (see Figure 13).

Layout rules in the CSS panel.

Figure 13. Layout rules in the CSS panel.

In addition to creating and attaching new rules, the CSS Styles panel lets you track the CSS rules and properties that affect the elements on the page. All mode lets you see all of the page’s rules at once, while Current mode lets you see the rules that apply to the current selection on the page. The CSS Styles panel also lets you modify CSS properties without opening an external style sheet.

There are a number of ways we could go about formatting your text. Beginners often create class rules and apply them to each paragraph, but that’s a very inefficient approach. It’s better to use CSS to apply an overall style first, and use classes and other CSS selectors only for those elements that you want to style differently.

For now, all you need is a nice font format and size, and since you want your format to be uniform across all three columns, you can simply define the font format in a rule for the body tag ( <body> ). The body tag is the topmost tag of the HTML page, which means that all other tags on the page (including all of our div tags) inherit the properties defined for the body tag. By defining your text properties in the body tag, you will effectively be defining text properties for all text that appears on the page.

  1. In the lower right-hand corner of the CSS Styles panel, click the New CSS Rule button.
  2. In the New CSS Rule dialog box, do the following:
    • Select Tag from the Selector Type pop-up menu.
    • Type or select body in the Selector Name text box.

    Note the description in the text box below the selector name. Dreamweaver is telling you that the rule you’re creating will apply to all <body> elements. That’s exactly what you want.

  3. Make sure check_cs5.css is selected from the Rule Definition pop-up menu.
  4. Click OK.The CSS rule definition dialog box appears, indicating that you are defining properties for the new body tag rule.
  5. Select the Type category in the Category column. (It should be selected by default.)
  6. In the Type category, do the following:
    • From the Font-family pop-up menu, select Trebuchet MS, Arial, Helvetica, sans-serif
    • Click the Color box and use the eyedropper tool to select black (#000).
    • Click Apply.

    As soon as you click Apply, all the text in Design view should be formatted with the new style (see Figure 14).

You can check the effect of your styles by clicking the Apply button.

Figure 14. You can check the effect of your styles by clicking the Apply button.

Tip: If you want to experiment with different styles, you can change the values in the CSS Rule Definition dialog box, and click Apply to see the effect immediately reflected in Design view.

  1. While you’ve got the CSS Rule Definition dialog open, you should set a background color for the <body> tag. Although current browsers set the background color to white, it’s generally recommended to set the color explicitly in your own style rules—and, of course, you can choose any color you like.Select Background from the Category list on the left.
  2. Click the Background-color color box, and select white (#FFF).
  3. Click OK to close the CSS Rule Definition dialog box.You’ll notice two things. One is that Dreamweaver has added the new body tag rule to the CSS Styles panel (see Figure 15).

The new body rule in the CSS Styles panel.

Figure 15. The new body rule in the CSS Styles panel.

The other thing you might notice is the asterisk (*) that appeared next to the check_cs5.css file name in the upper left-hand corner of your document (see Figure 16).

The asterisk in the Related Files toolbar reminds you to save the changes to the style sheet.

Figure 16. The asterisk in the Related Files toolbar reminds you to save the changes to the style sheet.

What Dreamweaver is showing you here is that you have an unsaved related file.

  1. Select File > Save All Related Files to save the changes you made to the style sheet.

Format headings and create links

Now you just need to do a couple more things to finish formatting the text in your columns.

Format headings

To format headings:

  1. In the left_column div, place the Insertion point after the ® symbol at the end of the first line, and press Enter (Windows) or Return (Mac OS X).Note that the Insertion point is now on a line above the following text. Open Split view to understand what has happened. There’s a line break ( <br /> ) tag immediately after the opening <p> tag (see Figure 17).

The text you pasted into the columns contains &lt;br /&gt; tags.

Figure 17. The text you pasted into the columns contains <br /> tags.

When you pasted the text from text.txt, the newline characters were converted to <br /> tags. This gives the impression of paragraphs, but causes problems for formatting the text correctly. Pressing Enter/Return created a closing </p> tag at the end of the first line, and an opening <p> tag at the beginning of the next line, but the <br />tag wasn’t removed, leaving too big a space between the paragraphs.

  1. Make sure the Insertion point is still in the same place, and press your down arrow once to move the Insertion point before the word The.
  2. Press Backspace to delete the unnecessary line break (see Figure 18).

The line break has gone, leaving two paragraphs.

Figure 18. The line break has gone, leaving two paragraphs.

This is a very important step. The main paragraph text must be completely separated from the heading before we apply a format to the heading.

  1. Click anywhere in the heading text. For example, click in the word Tesla. You do not need to select any text—you only need to make sure that the Insertion point is somewhere in the heading text.
  2. In the Property inspector (Window > Properties), make sure the HTML button on the left is selected.
  3. Select Heading 2 from the Format pop-up menu (see Figure 19).

Select Heading 2 from the Format pop-up menu in the HTML Property inspector.

Figure 19. Select Heading 2 from the Format pop-up menu in the HTML Property inspector.

The Inside Tesla Motors® heading changes to a Heading 2. The size and weight of the text you see here is the default size and weight for a Heading 2. In other words, you did not really need to apply any CSS to achieve this effect (though you could have!)

Now you’ll do the same thing with the remaining headings.

  1. In the center_column div, place the Insertion point after the word Figures at the end of the first line of text and press Enter (Windows) or Return (Mac).
  2. Press the down arrow once, to move the Insertion point before the word How at the beginning of the next line, and press Backspace to remove the line break.
  3. Click anywhere in the heading text. For example, click in the word Figures.
  4. In the Property inspector, select Heading 2 from the Format pop-up menu.The Facts and Figures heading changes to a Heading 2.
  5. Lastly, in the right_column div, place the Insertion point after the word Improvement at the end of the first line of text and press Enter (Windows) or Return (Mac OS X).
  6. Press the down arrow once to move the Insertion before the word Whether at the beginning of the next line, and press Backspace to remove the line break.
  7. Click anywhere in the heading text. For example, click in the word Improvement.
  8. In the Property inspector, select Heading 2 from the Format pop-up menu.The Today’s Self Improvement heading changes to a Heading 2.
  9. Save the page.

Create links

A link is a reference, inserted in a web page, that points to another document. You can turn almost any kind of asset into a link, but the most common kind of link is a text link. In this section, you’ll turn the “read more…” text in each of our three columns into links.

The check_cs5 site root folder contains a finished HTML page that you can link to (a news page for the magazine). You’ll use this page for all of the links in the columns, even though you would have distinct pages for each of these links if you were building a real site.

Note: The news.html page is a dummy page made up of images, and is not intended for practical use. A follow-up tutorial will later show you how to create a functioning version of the page using a database and PHP server-side technology.

  1. In the left_column div, select the “read more…” text at the end of the paragraph, including the periods (see Figure 20).Tip: Because there’s no gap between the text and the left side of the div, you might find it difficult to select the text from left to right. Click and drag from the right—it’s much easier.

Selecting text in the left_column div.

Figure 20. Selecting text in the left_column div.

  1. In the HTML Property inspector, click the folder icon next to the Link text box (see Figure 21).

Clicking the Folder icon in the Property inspector.

Figure 21. Clicking the Folder icon in the Property inspector.

  1. In the Select File dialog box, select the news.html file (which is in the same folder as index.html) and click OK (Windows) or Choose (Mac OS X).
  2. Click next to the “read more…” text to deselect the link. You’ll see that the text has transformed into a link, underlined and blue.
  3. Repeat the previous steps and link the “read more…” text in the remaining two columns to the news.html page. When you’re finished, your page should look as shown in Figure 22.

The three columns with linked text.

Figure 22. The three columns with linked text.

  1. Save the page.

You just created three links to a page that’s internal to our site. But you can also use the Link text box in the Property inspector to create links to external websites. To do so, simply select the text or element you want to link, and then type the website’s full URL in the Link text box of the Property inspector. For example, if you wanted to link the third “read more…” text in our example to adobe.com, you would select the text, type in the Link text box, and press Enter/Return.

Note: When linking to an external site, you must include the http:// at the beginning of the URL. If you omit it, the browser treats it as an internal link.

Preview the page

Design view gives you a reasonably good idea of what your page will look like on the web, but you must preview the page in Dreamweaver or in a browser to see the definitive end result. With Dreamweaver CS5, you can preview your page directly in the Document window using Live View. You can also compare how your site looks in leading browsers by launching BrowserLab.

Preview your page in Live View

To preview the page, ensure that the index.html page is open in the Document window, and click the Live View button (see Figure 23).

Click Live View to preview the page inside Dreamweaver.

Figure 23. Click Live View to preview the page inside Dreamweaver.

Dreamweaver displays a preview of your page, just as it would appear in a browser. The page does not look all that different, as Dreamweaver does a pretty good job of displaying pages in Design view as they would look in a browser; but you’ll notice that small changes occur when you enter Live view—the outlines for all of the div tags disappear, for example.

Dreamweaver Live View uses WebKit as its rendering engine—the same engine that powers the Apple Safari browser, and a host of other applications such as Google Chrome and Adobe AIR.

Check links in Live View

In Dreamweaver CS5, Live View works just like a real browser, allowing you to follow links. Hold down the Ctrl key (Windows) or Cmd key (Mac OS X) when you click a link, and Dreamweaver takes you to the target page within the Document window—even if the link points to an external page on a different site (assuming you’re connected to the internet at the time).

  1. Click the Live View button to view index.html as it looks in a standards-compliant browser.
  2. Hold down Ctrl/Cmd and click one of the “read more” links.The news.html page appears in the Document window (see Figure 24).

You can follow links to other pages in Live View in Dreamweaver CS5.

Figure 24. You can follow links to other pages in Live View in Dreamweaver CS5.

Notice that there’s a Browser Navigation bar at the top of the Document window. It works in the same way as you would expect in a browser with Backward and Forward buttons. The Home button takes you back to the page you started from. You can even type a completely different URL in the Address text box, and Dreamweaver loads it into Live View (as long as the site is accessible).

If you don’t want to hold down Ctrl/Cmd each time you click a link, select Follow Links Continuously from the Live View Options menu (see Figure 25).

Select the option to follow links continuously.

Figure 25. Select the option to follow links continuously.

However, this works only during the current Live View session. If you turn off Live View, you need to select this option again the next time you launch Live View.

  1. Click the Home icon in the Browser Navigation bar to return to index.html, and click Live View to turn it off.

Preview your page in BrowserLab

BrowserLab is an online Adobe service integrated directly into Dreamweaver CS5 that lets you see what your pages look like in a wide range of popular browsers on both Windows and Mac OS X, saving you the need to install multiple browsers and operating systems locally.

To use BrowserLab, you need an Adobe ID. If you registered your Adobe ID during the installation of Dreamweaver CS5 (or Creative Suite CS5), you’re ready to go. Otherwise, select Help > Register, and follow the instructions onscreen to register for CS Live Services.

  1. With index.html open in the Document window, open the BrowserLab panel by clicking its tab, or by selecting Window > BrowserLab. Make sure you’re connected to the internet, and that the menu option alongside the Preview button in the BrowserLab panel is set to Local, and click Preview.Alternatively, press Ctrl+Shift+F12 (Windows) or Shift+Cmd+F12 (Mac OS X).
  2. Dreamweaver opens BrowserLab in your default browser, and prompts you to sign in with your Adobe ID. It then uploads your page and all related files and assets to the BrowserLab server.After a short while (the time depends on the speed of your Internet connection), BrowserLab displays your page as it looks in a range of different browsers and operating systems. You can create your own subsets of browsers and operating systems to test in, view different ones side by side, or superimpose them in “onion skin” mode.Figure 26 shows index.html as it currently looks in Safari 4.0 on Mac OS X and Internet Explorer 6 on Windows XP.

Comparing the Check Magazine page in different browsers in BrowserLab.

Figure 26. Comparing the Check Magazine page in different browsers in BrowserLab.

If you look closely at the image on the right of Figure 26, you can see that Internet Explorer 6 leaves no gap between the main image and the image in the columns (Internet Explorer 7 does the same).

Note: When checking the page in BrowserLab, you’ll notice that the main image is not rendered in Firefox 2.0 on either Windows or Mac, because it’s a background image. The market share of Firefox 2.0 is estimated at about 0.6 percent and falling, so it can be ignored, particularly since the image is purely decorative.

  1. Switch back to Dreamweaver, and add the following style rule at the bottom of the check_cs5.css style sheet:

p { margin-top: 1em; }

This adds a margin of one em to the top of each paragraph. An em is a measurement borrowed from typography. In CSS, one em is equivalent to the height of the current font. When typing the rule, make sure there is no gap between the number and the unit. Type 1em, not 1 em.

  1. Save check_cs5.css, and click the Preview button in the BrowserLab panel to refresh the version on BrowserLab.
  2. Select Internet Explorer 6 in BrowserLab. The images at the top of the columns are now correctly positioned (see Figure 27).

BrowserLab confirms that the paragraph style has fixed the problem.

Figure 27. BrowserLab confirms that the paragraph style has fixed the problem.

  1. Select Internet Explorer 7. The images are correctly positioned.
  2. Check the other browsers. The images are now in the same position in all of them. By default, most browsers add a top margin equal to the height of one line at the top of every paragraph. It’s just Internet Explorer 6 and 7 that weren’t playing ball. The style rule brought them back into line without affecting the look in other, more standards-compliant browsers.
  3. Close your browser window or tab to exit BrowserLab.

Preview your page in a browser

Using BrowserLab to compare how your pages look in different browsers on different operating systems is important before you publish them on the Internet. But sometimes, you just want to take a quick look in a browser or two on your local computer. That’s where Preview in Browser comes in useful.

To preview the current page in your default browser, just press the F12 key (Windows) or Option+F12 (Mac OS X). You can also edit Dreamweaver Preferences to register other browsers.

  1. Select Edit > Preferences (Windows) or Dreamweaver > Preferences (Mac OS X) to open the Preferences panel.
  2. Select Preview in Browser from the Category list on the left.
  3. Dreamweaver might already have detected other browsers on your computer. To add other browsers, click the plus button alongside Browsers to open the Add Browser dialog box.
  4. Type the name of the browser in the Name text box, and click the Browse button to navigate to the browser’s application file.
    • On Windows, this is normally the .exe file in the browser’s subfolder of C:\Program Files or C:\Program Files(x86).
    • On Mac OS X, select the browser’s name in the Applications folder.

    Tip: On Windows, Google Chrome is installed in a folder associated with your user account. To locate it, you need to enable the display of hidden files and folders. Right-click the application name in the Windows Start menu and select Properties to find the exact location.

  5. Select one of the browsers listed in the Browsers text area, and select the Secondary browser check box. To launch the current page in the Document window in your secondary browser, press Ctrl+F12 (Windows) or Shift+Opt+F12 (Mac OS X).
  6. To launch your page in a particular browser, select File > Preview in Browser, and choose the browser from the list. Alternatively, click the Preview/Debug in Browser button on the Document toolbar, and select a browser from the list (see Figure 28).

Select a browser from the list to preview your page locally.

Figure 28. Select a browser from the list to preview your page locally.

Note: For more information about working with Live View, see Previewing pages in Dreamweaver in Dreamweaver Help. For more information about previewing in browsers, see Previewing pages in browsers in Dreamweaver Help.

Your page is almost finished and ready for publication. In Part 4: Adding the main image text, you’ll add another div to the main image area and position it using CSS.