Chapter 8. Working with Text

IN THIS CHAPTER

  • Creating headlines in Dreamweaver

  • Adding and editing paragraphs

  • Dreamweaver Technique: Entering and Pasting Text

  • Running the Spell Checker

  • Automating your work with Find and Replace

  • Handling whitespace

  • Bringing Office documents online

  • Using special text formats

  • Working with HTML styles

  • Changing fonts, font size, and font color

  • Formatting dates

  • Inserting HTML comments

If content is king on the Web, then certainly style is queen; together they rule hand in hand. Entering, editing, and formatting text on a Web page is a major part of a Webmaster's job. Dreamweaver gives you the tools to make the task as clear-cut as possible. From headlines to comments, this chapter covers the essentials of working with basic text; inserting and formatting dynamic data is covered in Chapter 19.

At first, Web designers didn't have many options for manipulating text. However, now the majority of browsers understand a number of text-related commands, and the designer can specify the font as well as its color and size. Dreamweaver includes a range of text-manipulation tools. All these topics are covered in this chapter, along with an important discussion of how to manipulate whitespace on the Web page.

Starting with Headings

Text in HTML is primarily composed of headings and paragraphs. Headings separate and introduce major sections of the document, just as a newspaper uses headlines to announce a story and subheads to highlight essential details. HTML has six levels of headings; the syntax for the heading tags is <hn>, where n is a number from 1 to 6. The largest heading is <h1>, and the smallest is <h6>.

Note

Although Dreamweaver is capable of outputting several different types of Web pages—ASP, ColdFusion, JSP, and so on—after the page has been executed on the application server, straight HTML is returned to the visitor's browser. So even though you'll find numerous references to HTML pages throughout this chapter, understand that even though the pages may be stored as ASP pages or other types, HTML is the result.

Remember that HTML headings are not linked to any specific point size, unlike type produced in a page layout or word processing program. Headings in a Web document are sized relative to one another, and their final, exact size depends on the browser used. The sample headlines in Figure 8-1 depict the basic headings as rendered through Dreamweaver and as compared to the default paragraph font size. As you can see, some headings are rendered in type smaller than that used for the default paragraph. Headings are usually displayed with a boldface attribute.

Standard HTML allows six headings of different sizes.

Figure 8-1. Standard HTML allows six headings of different sizes.

Several methods set text as a particular heading size in Dreamweaver. In all cases, you first select the text you want to affect. If you are styling a single line or paragraph as a heading, just position the cursor anywhere in the paragraph to select it. If you want to convert more than one paragraph, click and drag out your selection.

Tip

You can't mix heading levels in a single paragraph. That is, you can't have a word with an <h1> heading in the same line with a word styled with an <h4> heading. Furthermore, headings belong to a group of HTML text tags called block elements. All block elements are rendered with a paragraph return both above and below, which isolates (blocks) the text. To work around both of these restrictions, use Cascading Style Sheets, described in Chapter 7, to achieve the effect of varying sizes for words within the same line or for lines of different sizes close to one another.

After the text for the heading is selected, choose your heading level in one of the following ways:

  • Choose Text

    Standard HTML allows six headings of different sizes.
  • Click the Heading 1, Heading 2, or Heading 3 button from the Text category of the Insert bar.

  • Make your selection from the Text Property inspector. (If it's not already open, display the Text Property inspector by selecting Window

    Standard HTML allows six headings of different sizes.

Tip

You can also use keyboard shortcuts for assigning headings. Headings 1 through 6 correspond to Ctrl+1 through Ctrl+6 (Command+1 through Command+6). The Paragraph option is rendered with Ctrl+Shift+P (Command+Shift+P); remove all formatting with Ctrl+0 (Command+0).

You can convert any paragraph or line into a heading through the Format options in the Text Property inspector.

Figure 8-2. You can convert any paragraph or line into a heading through the Format options in the Text Property inspector.

Headings are often used in a hierarchical fashion, largest to smallest—but you don't have to do it that way. You can have an <h3> line followed by an <h1> paragraph, if that's what your design needs.

Warning

Be careful when using the smallest headings, <h4> to <h6>; they are likely to be difficult to read on any resolution higher than 800 × 600.

Working with Paragraphs

Usually the bulk of text on any Web page is composed of paragraphs. Paragraphs in HTML are denoted by the <p> and </p> pair of tags. When your Web page is processed, the browser formats everything between those two tags as one paragraph and renders it to fit the user's screen, word wrapping as needed at the margins. Any additional line breaks and unnecessary whitespace (beyond one space between words and between sentences) in the HTML code are ignored.

Tip

In the earliest versions of HTML, paragraphs used just the opening <p> tag. Browsers rendered everything after a <p> tag as one paragraph, until they reached another <p> tag. As of HTML 3.2, however, an optional closing </p> tag was added. Because so many Web pages have been created with just the opening paragraph tag, most browsers still recognize the single-tag format, even though the latest versions of the HTML standard require the closing tag. Dreamweaver automatically inserts both the opening and closing tags when you create a paragraph. To be on the safe side in terms of future compatibility, enclose your paragraphs within both opening and closing tags when you do any hand-coding.

Dreamweaver starts a new paragraph every time you press Enter (Return) when composing text in the Document window. If you have the Code view or the Code inspector open when you work, you can see that Dreamweaver inserts the following code with each new paragraph:

<p>&nbsp;</p>

The code between the tags creates a nonbreaking space that enables the new line to be visible. You won't see the new line if you have just the paragraph tags with nothing in between (neither a character nor a character entity, such as &nbsp;):

<p></p>

When you continue typing, Dreamweaver replaces the nonbreaking space with your input, unless you press Enter (Return) again. Figure 8-3 illustrates two paragraphs with text followed by paragraphs with the nonbreaking space still in place.

Dreamweaver automatically wraps any text inserted into the Document window. If you press Enter (Return) without entering text, Dreamweaver enters paragraph tags surrounding a nonbreaking space (&nbsp; in HTML).

Figure 8-3. Dreamweaver automatically wraps any text inserted into the Document window. If you press Enter (Return) without entering text, Dreamweaver enters paragraph tags surrounding a nonbreaking space (&nbsp; in HTML).

You can easily change text from most other formats, such as a heading, to paragraph format. First, select the text you want to alter. Then, in the Property inspector, open the Format drop-down list and choose Paragraph. You can also choose Text

Dreamweaver automatically wraps any text inserted into the Document window. If you press Enter (Return) without entering text, Dreamweaver enters paragraph tags surrounding a nonbreaking space (&nbsp; in HTML).

All paragraphs are initially rendered on the page in the default font at the default size. The user can designate these defaults through the browser preferences, although most people don't bother to alter them. If you want to change the font name or the font size for selected paragraphs explicitly, use the techniques described in the upcoming section "Modifying Text Format" or use Cascading Style Sheets, described in Chapter 7.

Tip

Remember that you can always use the Tag Selector on the status bar to select and highlight any tag surrounding your current cursor position. This method makes it easy to see exactly what a particular tag is affecting.

By and large, the editing features of Dreamweaver are similar to other modern word processing programs—with one or two Web-oriented twists. Like other programs, Dreamweaver has Cut, Copy, and Paste options, as well as Undo and Redo commands.

The twists come from the relationship between the Design and Code views of the Document window, which give Dreamweaver special functionality for copying and pasting text and code. You learn how that works in the following sections.

Inserting text

You've already seen how you can position the cursor on the page and directly enter text. In this sense, Dreamweaver acts like a word processing program rather than a page layout program. On a blank page, the cursor starts at the top-left corner of the page. Words automatically wrap to the next line when the text exceeds the right margin. Press Enter (Return) to end the current paragraph and start the next one.

In previous versions of Dreamweaver, when you create a paragraph formatted as a heading and then press Enter (Return), the new paragraph is also formatted as a heading. Now you can control this behavior. If you select Edit

Inserting text

Cutting, copying, and pasting

Text can be moved from one place to another—or from one Web document to another—using the standard cut-and-paste techniques. No surprises here: Before cutting or copying anything, you must select it. Select by clicking the mouse at the beginning of the text you want to cut or copy, drag the highlight to the end of your selection, and then release the mouse button.

Here are some other selection methods:

  • Double-click a word to select it.

  • Move the pointer to the left margin of the text until the pointer changes to a right-facing arrow. Click once to highlight a single line. Click and drag down the margin to select a group of lines.

  • Position the cursor at the beginning of your selection. Hold down the Shift key and then click once at the end of the selection.

  • Select everything in the body of your document by using Edit

    Cutting, copying, and pasting
  • Use the Tag Selector in the status bar to select text or other objects contained within specific tags.

  • You can also select text by holding down the Shift key and using the right or left arrow key to select one character at a time. If you hold down Ctrl+Shift (Command+Shift), press the right or left arrow key to select one word at a time.

  • Hold down the Shift key and then press the up or down arrow key to select a line at a time. Pressing Ctrl+Shift (Command+Shift) as you press the up or down arrow key selects a paragraph at a time.

Dreamweaver provides quick access to the most common editing commands, such as Cut, Copy, and Paste, through the Standard toolbar. To enable the toolbar, choose View

Cutting, copying, and pasting

When you want to move a block of text, first select it and then use Edit

Cutting, copying, and pasting

To copy text, the procedure is much the same. Select the text using one of the preceding methods and then use Edit

Cutting, copying, and pasting

Using drag-and-drop

The other, quicker method for moving or copying text is the drag-and-drop technique. After you've selected your text, release the mouse button and move the cursor over the highlighted area. The cursor changes from an I-beam to an arrow. To move the text, click the selected area with the arrow cursor and drag your mouse to a new location. The arrow cursor now has a box attached to it, indicating that it is carrying something. As you move your cursor, a bar (the insertion point) moves with you, indicating where the text will be positioned. Release the mouse button to drop the text.

You can duplicate text in the same manner by holding down the Ctrl (Option) key as you drag and drop your selected text. When copying this way, the box attached to the cursor is marked with a plus sign (on Macintosh computers, the box is the same size as the text selection, and no plus sign appears).

To completely remove text, select it and then choose Edit

Using drag-and-drop

Inserting text from other text applications

The Paste command can also insert text from another program into Dreamweaver. If you cut or copy text from a file in any other program—whether it is a word processor, spreadsheet, or database program—Dreamweaver inserts it at the cursor position. The results of an ordinary Paste operation may be undesirable, however. To more closely control the text inserted into Dreamweaver, use Paste Special.

Paste Special allows you to choose exactly how you'd like the copied text inserted into your document. Choose from a range of options that give you the flexibility to add straight text, structured text, structured text with simple formatting, or fully formatted text. The options can be preset in the Copy/Paste category of the Preferences and adjusted on a case-by-case basis.

After you've copied text in another application, choose Edit

Inserting text from other text applications
  • Text Only: Pastes completely unformatted text; even line breaks or paragraphs are removed.

  • Text With Structure: Pastes unstyled text while retaining structured elements such as lists, paragraphs, line breaks, and tables.

  • Text With Structure Plus Basic Formatting: Adds simple formatting, such as bold, italic, and underline, to structured text. If the text is copied from an HTML document, the pasted text retains any HTML text style tags, including <b>, <i>, <u>, <strong>, <em>, <abbr>, and <acronym>.

  • Text With Structure Plus Full Formatting: Pasted text keeps all structure and formatting. If the copied text retains inline CSS styles, Dreamweaver pastes them as well.

Two other options are available for modifying your paste output. The Retain Line Breaks option maintains line breaks in pasted text; if you choose Text Only, this option is disabled. The Clean Up Word Paragraph Spacing option works with the Text With Structure and Text With Structure Plus Basic Formatting choices to remove additional space between paragraphs.

If you use the standard Paste command, Dreamweaver can insert only plain, unformatted text—any bold, italic, or other styling in the original document is not retained in Dreamweaver. Paragraph breaks, however, are retained and reproduced in two different ways. A single paragraph return becomes a line break (a <br> tag) in Dreamweaver, whereas text separated by two returns is formatted into two HTML paragraphs, using the <p>...</p> tag pair.

Note

If you need to import a great deal of text and want to retain as much formatting as possible, you can use another text application, such as Microsoft Word, to save your text as an HTML file. Then open that file in Dreamweaver with the Import

Inserting text from other text applications

Copying and pasting code

As mentioned earlier in this chapter, Dreamweaver includes a couple of twists to the standard Cut, Copy, and Paste operations. Dreamweaver's Design and Code views enable you to copy and paste both text and code.

Put simply, to copy only text from Dreamweaver to another application, use the Edit

Copying and pasting code

Within Dreamweaver itself, content copied from Design view and pasted in Code view using Edit

Copying and pasting code

Undo, redo, and the History panel

The Undo command has to be one of the greatest inventions of the 20th century. Make a mistake? Undo! Want to experiment with two different options? Undo! Change your mind again? Redo! The Undo command reverses your last action, whether you changed a link, added a graphic, or deleted the entire page. The Redo command enables you to reverse your Undo actions.

To use the Undo command, choose Edit

Undo, redo, and the History panel

Dreamweaver's implementation of the Undo command enables you to back up as many steps as set in Maximum Number of History Steps, found in the General category of Preferences. The History steps can even undo actions that took place before a document was saved. Note that the History panel has additional features besides multiple applications of the Undo command.

The complement to the Undo command is the Redo command. To reverse an Undo command, choose Edit

Undo, redo, and the History panel

Tip

The best use I've found for the Redo command is in concert with Undo. When I'm trying to decide between two alternatives, such as two different images, I'll replace one choice with another and then use the Undo/Redo combination to go back and forth between them. Because Dreamweaver replaces any selected object with the current object from the clipboard—even if one is a block of text and the other is an AP element—you can easily view two separate options with this trick. The History panel enables you to apply this procedure to any number of steps.

A variation of the Redo command is the Repeat command. When your last action was the Undo command, the Edit menu shows the Redo command. But if the last action you performed was not Undo, the Edit menu shows the Repeat command, which allows you to repeat your last action. You can use the same button on the Standard toolbar to Repeat and Redo. In addition, the Repeat command has the same keyboard shortcut as Redo: Ctrl+Y (Command+Y). The Repeat command is useful, for example, when you need to create several links to the same location. To do this, create the first link, and then select the next text you want to link and use the Repeat command to add the next link.

Note

Although the History panel enables you to replay any series of selected steps at the click of a button, you have to click that button every time you want to replay the steps. I developed a custom extension called Repeat History with which you can repeat selected steps any number of times. You'll find Repeat History in the Additional Extensions folder on the CD-ROM.

Checking Your Spelling

A typo can make a significant impression, and not the one you want to make. Not many things are more embarrassing than showing a new Web site to a client and having that client point out a spelling error. Dreamweaver includes an easy-to-use Spell Checker to avoid such awkward moments. Make it a practice to spell check every Web page before it's posted online.

You start the process by choosing Text

Checking Your Spelling
Dreamweaver's Spell Checker double-checks your spelling and can find the typos on any Web page.

Figure 8-4. Dreamweaver's Spell Checker double-checks your spelling and can find the typos on any Web page.

After you've opened the Check Spelling dialog box, Dreamweaver begins searching your text for errors. Unless you have selected a portion of your document, Dreamweaver checks the full document, regardless of where your cursor is placed. When text is selected, Dreamweaver checks the selection first and then asks if you'd like to do the entire document.

Dreamweaver checks your Web page text against two dictionaries: a standard dictionary for your chosen language and a personal dictionary to which you can add words. If the Spell Checker finds any text that is not in either of the program's dictionaries, the text is highlighted in the Document window and appears in the Word Not Found In Dictionary field of the dialog box. A list of suggested corrections appears in the Suggestions list box, with the topmost one highlighted and also displayed in the Change To box. If Dreamweaver cannot find any suggestions, the Change To box is left blank. At this point, you have the following options:

  • Add To Personal: Click this button to include the word in your personal dictionary and prevent Dreamweaver from tagging it as an error in the future.

  • Ignore: Click this button when you want Dreamweaver to leave the currently highlighted word alone and continue searching the text.

  • Change: If you see the correct replacement among the list of suggestions, highlight it and click the Change button. If no suggestion is appropriate, type the correct word into the Change To text field and then click this button.

  • Ignore All: Click this button when you want Dreamweaver to disregard all occurrences of this word in the current document.

  • Change All: Click this button to replace all instances of the current word within the document with the word in the Change To text field.

Using Find and Replace

Dreamweaver's Find and Replace features are both timesaving and lifesaving (well, almost). You can use Find and Replace to cut your input time substantially by searching for abbreviations and expanding them to their full state. You can also find a client's incorrectly spelled name and replace it with the correctly spelled version—that's a lifesaver! However, that's just the tip of the iceberg when it comes to what Find and Replace can really do. The Find and Replace engine should be considered a key power tool for any Web developer. Not only can you search multiple files, but you can also easily check the code separately from the content.

Here's a short list of what the Find and Replace feature makes possible:

  • Search the Document window to find any type of text.

  • Search the underlying HTML to find tags, attributes, or text enclosed within tags.

  • Look for text within specific tags with specific attributes—or look for text that's outside of a specific tag with specific attributes.

  • Find and replace patterns of text, using wildcard characters called regular expressions.

  • Apply any of the preceding Find and Replace operations to the current document, the current site, any folder, or any group of selected files.

The basic command, Find and Replace, is found with its companion, Find Next, under the Edit menu. You can use both commands in either Dreamweaver's Design or Code view. Although invoked by a single command, the Find feature can be used independently or in conjunction with Replace.

Find and Replace operations can be applied to one or a series of documents. In addition to searching all or part of the current document, you can also apply Find and Replace to all the files in a folder or an entire site. Furthermore, individual files selected in the Files panel are also searchable.

Finding on the visual page

The most basic method of using Find and Replace takes place in the Document window. Whenever you need to search for any text that can be seen by the public on your Web page—whether it's to correct spelling or change a name—Dreamweaver makes it fast and simple.

The Find and Replace dialog box, unlike most of Dreamweaver's dialog boxes, is actually a nonmodal window. This technical term just means that you can easily move back and forth between your Document window and the Find and Replace dialog box without having to close the dialog box first, as you do with the other Dreamweaver dialog boxes.

Whether you are working with a long, involved document or you just want to look in a particular area, you'll welcome Dreamweaver's new capability to search a selection. Just highlight the text you want to search and, in the Find and Replace dialog box, choose Selected Text from the Find In drop-down list. You can search just selected code, too.

To find some text on your Web page, follow these steps:

  1. From the Document window, choose Edit

    Finding on the visual page
  2. In the Find and Replace dialog box, shown in Figure 8-5, make sure that Text is the selected Search option.

    The Find and Replace dialog box.

    Figure 8-5. The Find and Replace dialog box.

  3. In the text field next to the Search option, type the word or phrase you're looking for.

    Tip

    If you select your text before launching the Find dialog box, it automatically appears in the Search text field if it contains fewer than 255 characters. Should you select text containing a greater number of characters, Dreamweaver assumes you want to search the selection and keeps the Search field clear.

  4. Select the appropriate search options, if any:

    • If you want to find an exact replica of the word as you entered it, select the Match Case checkbox; otherwise, Dreamweaver searches for all variations of your text, regardless of case.

    • To force Dreamweaver to disregard any whitespace variations, such as additional spaces, hard spaces, or tabs, select the Ignore Whitespace Differences option. For most situations, it's a good idea to leave this default option enabled.

    • Selecting Use Regular Expressions enables you to work with Dreamweaver's wildcard characters (discussed later in this section). Use Regular Expressions and Ignore Whitespace Differences are mutually exclusive options.

  5. Click the Find Next button to begin the search from the cursor's current position.

    • If Dreamweaver finds the selected text, it highlights the text in the Document window.

    • If Dreamweaver doesn't find the text in the remaining portion of the document, it automatically continues the search from the beginning of the document until the entire document has been checked.

    • If Dreamweaver doesn't locate the search term, it displays a message saying the term has not been found.

  6. If you want to look for the next occurrence of your selected text, click the Find Next button again.

  7. You can enter other text to search or exit the Find dialog box by clicking the Close button.

The text you enter in the Find and Replace dialog box is kept in memory until it's replaced by your next use of the Find feature. After you have executed the Find command once, you can continue to search for your text without redisplaying the Find and Replace dialog box, by selecting Edit

The Find and Replace dialog box.

Instead of locating one instance of your text at a time, you can also look for all occurrences of your text at once. To do this, open and set up the Find and Replace dialog as previously described, but choose Find All instead of Find Next. When you choose Find All, Dreamweaver closes the Find and Replace dialog box and opens the Search panel. The Search panel displays each found occurrence on a separate line, as shown in Figure 8-6. A message at the bottom of the Search panel also tells you how many occurrences of your selection, if any, were found. If you want to search for a different term, click the Find and Replace button (the small green triangle) in the Search panel to reopen the Find and Replace dialog box.

The Search panel displays results of a Find All command.

Figure 8-6. The Search panel displays results of a Find All command.

Tip

To quickly move from one found selection to another in the Document window, double-click an entry in the Search panel. Dreamweaver highlights the selection, scrolling the Document window, if necessary. Note, however, that the results listed in the Search panel may take you to the wrong location if you add or remove content in the document after you perform the search.

If you perform two Find All operations in a row, the Search panel automatically clears the results of the first search and replaces them with the results of the new search. To manually clear the Search panel, right-click (Control+click) and choose Clear Results.

Warning

If you edit the document after performing a Find All, the results of the search may no longer be valid. In this situation, double-clicking an item in the Search panel may no longer take you to the correct place in the document. If you have added or removed text in the document after performing a Find All, perform the search again by clicking the Find and Replace button (the small green triangle) in the Search panel to reopen the Find and Replace dialog box. If no text is selected in the Document window before you open the Find and Replace dialog box, the search parameters should automatically be set up; you just click Find All again.

When you replace text in the Document window, it is replaced regardless of its formatting. For example, suppose you have the following paragraph:

Mary's accusation reminded Jon of studying synchrones in high school. Synchrones, he recalled, were graphs in which the lines constantly approached zero, but never made it. "Yeah," he thought, "That's me, all right. I'm one big synchrone."

Upon discovering that synchrone should actually be asymptote, you could use the Find and Replace feature to replace all the plain, italic, and bold versions of the synchrone text simultaneously.

Tip

It's possible to alter formatting as well—to change all the formatting to bold only, for example—but for that you need to perform your Find and Replace operations on the underlying code, as discussed in the following section.

Follow these steps to use Dreamweaver's Replace feature in the Document window:

  1. Choose Edit

    The Search panel displays results of a Find All command.
  2. In the Find and Replace dialog box, make sure that Text is the selected Search option and then, in the text field next to the Search option, type the word or phrase you're looking for. You can also copy and paste text from the Document window into the Search field.

  3. In the Replace With text field, type the substitute text.

    Tip

    Need more room for your Find or Replace entries? The Find and Replace dialog box can be widened by dragging the border as you would a window; Macintosh users should drag the lower-right corner as usual.

  4. Click the Find Next button. Dreamweaver begins searching from the current cursor position. If Dreamweaver finds the text, it is highlighted.

  5. To replace the highlighted occurrence of the text, click the Replace button. Dreamweaver replaces the found text with the substitute text and then automatically searches for the next occurrence.

  6. If you want to replace all instances of the Search text, click the Replace All button. When Dreamweaver has found all the occurrences of your Search text, it displays a message telling how many replacement operations were made.

Warning

The Search panel applies to Find operations, but not to Replace operations. When you click Replace All, Dreamweaver does not update the Search panel to list items that have been replaced. Further, if you click Find All and then perform a Replace All, the previous results in the Search panel may no longer correctly reflect the location of the text you just replaced, and changed items in the Search panel are not flagged.

Tip

To rerun individual Find and Replace operations, highlight the appropriate step in the History panel (choose Window

Storing and Retrieving Queries

Searching the code

The power curve ramps up significantly when you start to explore Dreamweaver's Find and Replace capabilities for HTML code. Should your client decide that he wants the company's name to appear in blue, bold, 18-point type throughout the 300-page site, you can accommodate him with a few keystrokes—instead of hours of mind-numbing grunt work.

You can perform three different types of searches that use the HTML in your Web page:

  • You can search for text anywhere in the HTML code. With this capability, you can look for text within alt or any other attribute—and change it.

  • You can search for text relative to specific tags. Sometimes you need to change just the text contained within the <b> tag and leave all other matching text alone.

  • You can search for specific HTML tags and/or their attributes. Dreamweaver's Find and Replace feature gives you the capability to insert, delete, or modify tags and attributes.

Looking for text in the code

Text that appears onscreen is often replicated in various sections of your off-screen HTML code. It's not uncommon, for example, to use the alt attribute in an <img> tag that repeats the caption under the picture. What happens if you replace the wording using the Find and Replace dialog box with the Search field set to Text? You're still left with the task of tracking down the alt attribute and making that change as well. Dreamweaver enables you to act on both content and programming text in one operation—a major savings in time and effort, not to mention aggravation.

To find and replace text in both the content and the code, follow these steps:

  1. Choose Edit

    Looking for text in the code
  2. Select the parameters of your search from the Find In option: Current Document, Entire Current Local Site, Selected Files In Site, or Folder. If you choose Selected Files In Site, select the files of interest in the Site panel.

  3. From the Search drop-down list, select the Source Code option.

  4. Enter the text you're searching for in the text field next to the Search option.

  5. If you are replacing, enter the new text in the Replace With text field.

  6. Select any options desired: Match Case, Ignore Whitespace Differences, or Use Regular Expressions.

  7. Choose your Find/Replace option: Find Next, Find All, Replace, or Replace All. If you are in Design view, the Code inspector opens.

  8. If Dreamweaver hasn't automatically closed the Find and Replace dialog box (it closes automatically for the Find All and Replace All commands), click Close when you are finished.

Warning

As with all Find and Replace operations—especially those in which you decide to Replace All—you need to exercise extreme caution when replacing text throughout your code. If you're unsure about what's going to be affected, choose Find All first and, with Code view or Code inspector open, step through all the selections. You do this to be positive that no unwanted surprises occur. Should you replace some code in error, you can always undo the operation—but only if the document is open. Replacing text or code in a closed file—as is done when the operation is performed on a folder, the current site, or selected files in the Site panel—is not undoable. Therefore, it is wise to back up your site before performing a Replace All operation.

Using advanced text options in Find and Replace

In Find and Replace operations, the global Replace All isn't appropriate for every situation; sometimes you need a more precise approach. Dreamweaver enables you to fine-tune your searches to pinpoint accuracy. You can look for text within particular tags—and even within particular tags with specific attributes. Moreover, you can find (and replace) text that is outside of particular tags with specific attributes.

Dreamweaver assists you by providing a drop-down list of standard tags. The tags shown depend on the type of document you are viewing, as determined by the filename extension of the open file. For example, although most document types see HTML tags, a document with the .cfm extension would also see ColdFusion tags. You can also search for your own custom tags. In addition, you don't have to try to remember which attributes go with which tag; Dreamweaver supplies you with a context-sensitive list of attributes that changes according to the tag selected.

In addition to using the tag's attributes as a search filter, Dreamweaver can also search within the tag for text or another tag. Most HTML tags are so-called container tags that consist of an opening tag and a closing tag, such as <em> and </em>. You can set up a filter to look for text surrounded by a specific tag pair—or text outside of a specific set of tags. For example, if you are searching for the word big

The big, red boat was a <em>big</em> waste of money.

you can build a Find and Replace operation that changes one instance of the word (big, red) but not the other (<em>big</em>)—or vice versa.

To look for text in or out of specific tags and attributes, follow these steps:

  1. Choose Edit

    Using advanced text options in Find and Replace
  2. Select the parameters of your search from the Find In option: Current Document, Current Site, Folder, or Selected Files In Site.

  3. From the Search drop-down list, select the Text (Advanced) option. The Add (+) and Remove (–) tag options are made available, as shown in Figure 8-7.

    The advanced text features of Find and Replace enable you to manipulate text and code simultaneously.

    Figure 8-7. The advanced text features of Find and Replace enable you to manipulate text and code simultaneously.

  4. Enter the text you're searching for in the text field next to the Search drop-down list.

  5. Select either Inside Tag or Not Inside Tag from the drop-down list. Remember that Inside Tag refers to text that is enclosed within a beginning and ending tag pair, such as <h2></h2>.

  6. Select the tag to include or exclude from the adjacent drop-down list or type your own tag.

  7. To add a further restriction on the search, click the Add (+) button. Another line of search options is added to the dialog box.

  8. Select the additional search filter. The available options are listed in Table 8-1.

    Table 8-1. Search Filters

    Filter

    Description

    With Attribute

    Enables you to select any attribute from the adjacent drop-down list. You can set this attribute to be equal to, less than, greater than, or not equal to any given value by choosing from the available drop-down lists.

    Without Attribute

    Finds text within a particular tag that does not include a specific attribute. Choose the attribute from the adjacent drop-down list.

    Containing

    Searches the tag for either specified text or another user-selectable tag found within the initial tag pair.

    Not Containing

    Searches the tag for either text or a tag not found within the initial tag pair.

    Inside Tag

    Enables you to look for text that is within two (or more) sets of specific tags.

    Not Inside Tag

    Enables you to look for text that is in one tag, but not in another tag, or vice versa.

  9. To continue adding filter conditions, click the Add (+) button and repeat step 8.

  10. To remove a filter condition, click the Remove (–) button.

  11. If you are replacing text, enter the new text in the Replace With text field.

  12. Select any options you want: Match Case, Ignore Whitespace Differences, or Use Regular Expressions.

  13. Choose your Find/Replace option: Find Next, Find All, Replace, or Replace All.

Tip

You can continue to add conditions by clicking the Add (+) button. In fact, I was able to add so many conditions that the Find/Replace dialog box began to disappear off the screen (although I wouldn't recommend this in practice). To quickly erase all conditions, change the Search option to Text or Source Code and then change it back to Text (Advanced).

Replacing HTML tags and attributes

Imagine a new edict has come down from the HTML gurus of your company: No longer is the <b> tag to be used to indicate emphasis; from now on, use only the <strong> tag. Oh, and by the way, change all the existing pages—all 3,000+ Web and intranet pages—so that they're compliant. Dreamweaver makes short work out of nightmare situations such as this by giving you the power to search and replace HTML tags and their attributes.

But Dreamweaver doesn't stop there. Not only can you replace one tag with another; you can also perform the following:

  • Change or delete the tag (with or without its contents).

  • Set an attribute in the tag to another value.

  • Remove any or all attributes.

  • Add text and/or code before or after the starting or the ending tag.

To alter your code using Dreamweaver's Find and Replace feature, follow these steps:

  1. As with other Find and Replace operations, choose Edit

    Replacing HTML tags and attributes
  2. Select the parameters of your search from the Find In drop-down list: Current Document, Entire Current Local Site, Folder, or Selected Files In Site.

  3. From the Search drop-down list, select the Specific Tag option.

    The dialog box changes to include the tag functions.

  4. Select the desired tag from the option list next to the Search drop-down list.

    Tip

    You can either scroll down the list box to find the tag or you can type the first letter of the tag in the box. Dreamweaver scrolls to the group of tags that begin with that letter when the list is visible. To scroll further in the list, type the second and subsequent letters, or use the down or up arrow keys.

  5. You can limit the search by specifying an attribute and value or with other conditions, as discussed in detail in the previous section.

    Note

    If you want to search for just a tag, click the Remove (–) button to eliminate the additional condition.

  6. Make a selection from the Action list shown in Figure 8-8.

    The Action list enables you to replace tags or modify them by setting the existing attributes or adding new ones.

    Figure 8-8. The Action list enables you to replace tags or modify them by setting the existing attributes or adding new ones.

    The Action list options are described in Table 8-2.

    Table 8-2. Action List Options

    Action

    Description

    Replace Tag & Contents

    Substitutes the selected tag and all included content with a text string; the text string can include HTML code

    Replace Contents Only

    Changes the content between the specified tags to a given text string, which can also include HTML code

    Remove Tag & Contents

    Deletes the tag and all contents

    Strip Tag

    Removes the tag but leaves the previously enclosed content

    Change Tag

    Substitutes one tag for another

    Set Attribute

    Sets an existing attribute to a new value or inserts a new attribute set to a specific value

    Remove Attribute

    Deletes a specified attribute

    Add Before Start Tag

    Inserts a text string (with or without HTML) before the opening tag

    Add After End Tag

    Inserts a text string (with or without HTML) after the ending tag

    Add After Start Tag

    Inserts a text string (with or without HTML) after the opening tag

    Add Before End Tag

    Inserts a text string (with or without HTML) before the end tag

    Note

    Not all the options listed in the preceding list are available for all tags. Some so-called empty tags, such as <img>, consist of a single tag, not tag pairs. Empty tags have only the Replace Tag and Remove Tag options (instead of Replace Tag & Contents, Replace Contents Only, and Remove Tag & Contents) and the Add Before and Add After options (instead of Add Before Start Tag, Add After Start Tag, Add Before End Tag, and Add After End Tag).

  7. Select any options desired: Match Case, Ignore Whitespace Differences, or Use Regular Expressions.

  8. Choose your Find/Replace option: Find Next, Find All, Replace, or Replace All.

Tip

You don't have to apply a single action to all the instances Dreamweaver locates if you choose Find All. In the Search panel, select a single item and then choose Replace. Dreamweaver makes the revision and places a green dot next to the item so you can tell it has been altered. If you want, you can then select another item from the list, choose a different action, and select Replace.

Concentrating your search with regular expressions

As powerful as all the other Find and Replace features are, they are boosted to a higher level of flexibility with the addition of regular expressions. I've referred to regular expressions as being similar to wildcards in other programs, but their capabilities are actually far more extensive.

Regular expressions are best described as a text pattern matching system. If you can identify any pattern in your text, you can manipulate it with regular expressions. What kind of pattern? Imagine you have a spreadsheet-like table with lots of numbers, showing both dollars and cents, mixed with explanatory text. With regular expressions, you can match the pattern formed by the dollar sign and the decimal point and reformat the entire table, turning all the figures deep blue with a new font—all in one Find and Replace operation.

Note

If you're into Unix, you recognize regular expressions as being very close to the grep utility—grep, by the way, stands for Get Regular Expressions and Print. The Find and Replace feature in BBEdit, available only on a Macintosh, also features a grep-like syntax.

You can apply regular expressions to any of the types of Find and Replace operations previously discussed by just clicking the Use Regular Expressions checkbox. Note that when you select Use Regular Expressions, the Ignore Whitespace Differences option is deselected. This is because the two options are mutually exclusive.

The most basic regular expression is the text itself. If you enable the feature and then enter th in the Search text field, Dreamweaver locates every example of th in the text and/or source. Although this capability by itself has little use beyond what you can also achieve with standard Find and Replace operations, it's important to remember this functionality as you begin to build your patterns.

Warning

When entering text in the Search field of the Find and Replace dialog box, do not include any extra spaces after your search string. Dreamweaver interprets the spaces as part of your search string, and the search only finds your text when it is followed by a space.

Wildcard characters

Initially, it's helpful to be able to use what are traditionally known as wildcards—characters that match certain different types of characters. The wildcards in regular expressions represent single characters and are described in Table 8-3. In other words, no single regular expression represents all the characters, as the asterisk does when used in PC file searches (such as *.*). However, such a condition can be represented with a slightly more complex regular expression (described later in this section).

Table 8-3. Regular Expression Wildcard Characters

Character

Matches

Example

.

Any single character, including letters, numbers, spaces, punctuation, control characters (like line feed), and so on

w.c matches wacky and How could you? but not watch.

w

Any single alphanumeric character, including the underscore

wwc matches wac ky and W3C but not How could you?

W

Any single non-alphanumeric character

jboyWidest.com matches .

d

Any single numeric character 0–9

ydk matches Y2K.

D

Any single nonnumeric character

D2D matches Y2K and H2O.

s

Any single whitespace character, including space, nonbreaking space, tab, form feed, or line feed

smedia matches the media but not Macromedia.

S

Any single non-whitespace character

Smedia matches media but not the media.

A tab character

Matches any single tab character in the HTML source.

f

Form feed

Matches any single form-feed character in the HTML source.

A form feed is a control character used to force a page break when printing. Although unlikely, it is possible for this character to appear in your HTML document if you converted a print document to HTML. Most browsers ignore the form-feed character, but you might want to search for and remove the form feed using the f regular expression. A form feed is more likely to occur in a text document.

Line feed

Matches any single line-feed character in the HTML source.

Carriage return

Matches any single carriage-return character in the HTML source.

Tip

The backslash character () is used to escape special characters so that they can be included in a search. For example, if you want to look for an asterisk, you need to specify it as follows: *. Likewise, when trying to find the backslash character, precede it with another backslash character: \.

Matching character positions and repeating characters

With regular expressions, not only can you match the type of character, but you can also match its position in the text. This feature enables you to perform operations on characters at the beginning, end, or middle of the word or line. Regular expressions also enable you to find instances in which a character is repeated an unspecified number of times or a specific number of times. Combined, these features broaden the scope of the patterns that can be found. Table 8-4 details the options available for matching by text placement and character repetition.

Table 8-4. Regular Expression Character Positions and Repeating Characters

Character

Matches

Example

^

If searching text in the current document, this only finds the search string if it immediately follows the cursor. If searching source code or searching text in multiple documents, this regular expression only finds the search string if it is at the beginning of the document.

If searching text in the current document, ^l matches the first l in Call me Ishmael. only if the cursor is positioned after the a in the word Call. Clicking Find Next would find the second l in Call, but clicking Next again would not find the l in Ishmael because the character immediately following the cursor is not an l. If searching source code, ^< matches the opening < in the HTML <!DOCTYPE . . . > statement, assuming the < is the first character in the document.

$

End of a document

d$ matches the final d in Be afraid. Be very afraid if that is the last character in the document.



A word boundary, such as a space or carriage return.

text matches textbook but not SimpleText.

B

A nonword boundary inside a word.

Btext matches SimpleText but not textbook.

*

The preceding character zero or more times.

b*c matches BBC and the cold.

In the first example, both B's and the C match because the expression b*c causes Dreamweaver to look for any number of b's followed by a c. In the second example, only the c matches because b* means to search for zero or more instances of the b.

+

The preceding character one or more times.

b+c matches BBC but not cold.

?

The preceding character zero or one time.

ac?e matches ace and aerie but not axiomatic.

{n}

Exactly n instances of the preceding character.

e{2} matches reed and each pair of two e's in Aieeeeeeee!; but nothing in Dreamweaver.

{n,m}

A minimum of n and a maximum of m instances of the preceding character.

C{2,4} matches #CC00FF and #CCCC00, but not the full string #CCCCCC.

If you searched with the regular expression C{2,4}, it would first locate the first four C's in the string #CCCCCC. If you clicked Find Next, the search would locate the last two C's in the string because the search is looking for two, three, or four C's in a row.

Matching character ranges

Beyond single characters, or repetitions of single characters, regular expressions incorporate the capability of finding or excluding ranges of characters. This feature is particularly useful when you're working with groups of names or titles. Ranges are specified in set brackets. A match is made when any one of the characters within the set brackets, not necessarily all the characters, is found. Descriptions of how to match character ranges with regular expressions can be found in Table 8-5.

Table 8-5. Regular Expression Character Ranges

Character

Matches

Example

[abc]

Any one of the characters a, b, or c

[lmrt] matches the individual l and m's in lemmings, and the r and t in roadtrip.

[^abc]

Any character except a, b, or c

[^etc] matches each character in GIFs, but not etc in the phrase GIFs etc.

[a-z]

Any character in the range from a to z

[l-p] matches l and o in lowery, and m, n, o, and p in pointman.

x|y

Either x or y

boy|girl matches both boy and girl.

Using grouping with regular expressions

All the regular expressions described previously relate to finding a certain string of text within your documents. But after you've located a particular string using regular expressions, how can you use that particular string in the Replace With field? For example, the following list of names:

  • John Jacob Jingleheimer Schmidt

  • James T. Kirk

  • Cara Fishman

can be rearranged so that the last name is first, separated by a comma, like this:

  • Schmidt, John Jacob Jingleheimer

  • Kirk, James T.

  • Fishman, Cara

Dreamweaver enables replacement of regular expressions through grouping expressions. Grouping is perhaps the single most powerful concept in regular expressions. With it, any matched text pattern is easily manipulated. To group a text pattern, enclose it in parentheses in the Find text field. Regular expressions can manage up to nine grouped patterns. In the Replace text field, each grouped pattern is designated by a dollar sign ($) in front of a number (1–9) that indicates the position of the group. For example, enter $3 in the Replace With box to represent the third grouped pattern in the Find box.

Warning

Remember that the dollar sign is also used after a character or pattern to indicate the last character in a line in a Find expression.

Table 8-6 shows how regular expressions use grouping.

Table 8-6. Regular Expressions Grouping

Character

Matches

Example

(p) (entered in the Find In box)

Any pattern p

(bw*).(w*) matches two patterns, the first before a period and the second, after, such as in a filename with an extension. The backslash before the period escapes it so that it is not interpreted as a regular expression.

$1, $2 . . . $9 (entered in the Replace With box)

The nth pattern noted with parentheses

If the Search field contains the pattern (bw*).(w*), and the Replace With field contains the pattern $1's extension is ".$2", Chapter09.txt would be replaced with Chapter09's extension is ".txt".

Controlling Whitespace

Whitespace refers to any portion of the page that doesn't contain text, images, or other objects. It includes the space between words and the space above and below paragraphs. This section introduces ways to adjust paragraph margins and the spacing between paragraphs.

Indenting text

In Dreamweaver, you cannot indent text as you do with a word processor. Tabs normally have no effect in HTML. One method to indent a paragraph's first line uses nonbreaking spaces, which can be inserted with the keyboard shortcut Ctrl+Shift+Spacebar (Command+Shift+Spacebar). Nonbreaking spaces are an essential part of any Web designer's palette because they provide single-character spacing—often necessary to nudge an image or other object into alignment. You've already seen the code for a nonbreaking space—&nbsp;—that Dreamweaver inserts between the <p>...</p> tag pair to make the line visible.

You can optionally configure Dreamweaver to insert nonbreaking spaces in situations where it would normally ignore the spaces that you type. For example, whenever you type more than one space in a row or when you enter a space at the beginning of a paragraph, HTML, and therefore Dreamweaver, ignores the space. However, if you choose Edit

Indenting text

Tip

If you normally create paper documentation, you may be used to adding two spaces between sentences. For online documentation, use only a single space after a period. Adding two spaces not only goes against the norm, it's more work and can increase your file size by inserting all those extra nonbreaking spaces!

Dreamweaver offers other methods for inserting a nonbreaking space. You can enter its character code—&nbsp;—directly into the HTML code or you can use the Nonbreaking Space button in the Characters menu in the Text category of the Insert bar. You can also style your text as preformatted; this technique is discussed later in this chapter.

Tip

Cascading Style Sheets offer another method for indenting the first line of a paragraph. You can set an existing HTML tag, such as <p>, to any indent amount using the Text Indent option found on the Block panel of the Style Sheet dialog box. You can find a full discussion of text indent and other style sheet controls in Chapter 7.

Working with preformatted text

Browsers ignore formatting niceties considered irrelevant to page content: tabs, extra line feeds, indents, and added whitespace. You can force browsers to read all the text, including whitespace, exactly as you have entered it by applying the preformatted tag pair <pre>...</pre>. This tag pair directs the browser to keep any additional whitespace encountered within the text. By default, the <pre>...</pre> tag pair also renders its content with a monospacefont such as Courier. For these reasons, the <pre>...</pre> tag pair was used to lay out text in columns in the early days of HTML before tables were widely available.

You can apply the preformatted tag through the Property inspector, the Insert bar, or the menus. Regardless of the technique for inserting preformatted text, it is easiest to work in Code and Design views—applying changes in Code view and seeing the result in Design view. Select the text, or position the cursor where you want the preformatted text to begin; then use one of these methods to insert the<pre>...</pre> tags:

  • In the Property inspector, open the Format list box and choose Preformatted.

  • On the Insert bar, choose the Text category and click the Preformatted Text button.

  • Choose Text

    Working with preformatted text
  • Choose Insert

    Working with preformatted text

The <pre> tag is a block element format, like the paragraph or the headings tags, rather than a style. This designation as a block element format has two important implications. First, you can't apply the <pre>...</pre> tag pair to part of a line; when you use this tag pair, the entire paragraph is altered. Second, you can apply styles to preformatted text—this enables you to increase the size or alter the font, but at the same time maintain the whitespace feature made possible with the <pre> tag. All text in Figure 8-9 uses the <pre> tag; the column on the left is the standard output with a monospace font; the column on the right uses a different font in a larger size.

The <br> tag

Just like headings, the paragraph tag falls into the class of HTML objects called block elements. As such, any text marked with the <p>...</p> tag pair is always rendered with an extra line above and below the text. To have a series of blank lines appear one after the other, use the break tag <br>.

Note

In XHTML documents, the break tag is coded as <br />. Dreamweaver inserts the correct tag based on the document type.

Break tags are used within block elements, such as headings and paragraphs, to provide a line break where the <br> is inserted. Dreamweaver provides two ways to insert a <br> tag: Choose the Line Break button from the Characters menu in the Text category of the Insert bar, or use the keyboard shortcut Shift+Enter (Shift+Return).

Figure 8-10 demonstrates the effect of the <br> tag. The menu items in Column A on the left are the result of using the <br> tag within a paragraph. In Column B on the right, paragraph tags alone are used. The <h1> heading is also split at the top with a break tag to avoid the insertion of an unwanted line.

You can enable Dreamweaver to mark <br> tags with a symbol: a gold shield with the letters BR and the standard Enter/Return symbol. To make the break symbol visible, you must first choose Edit

The <br> tag
Preformatted text gives you full control over the line breaks, tabs, and other whitespace in your Web page.

Figure 8-9. Preformatted text gives you full control over the line breaks, tabs, and other whitespace in your Web page.

Break tags, denoted by shield symbols, wrap your lines without the additional line spacing created by <p> tags.

Figure 8-10. Break tags, denoted by shield symbols, wrap your lines without the additional line spacing created by <p> tags.

Working with Microsoft Office Documents

The ubiquitous nature of Microsoft Office has intricately tied Word and Excel to the Web. Quite often, content stored in documents from these programs must be integrated into a Web page. Putting a meeting agenda drafted in Word or a production schedule laid out in Excel on the Web are just some of the tasks faced—and dreaded—by office personnel every day. Dreamweaver provides a number of methods to ease the transition from offline Office documents to online content. No matter the path you take, you'll have a range of options to paste your content how you want it to appear.

Copying and pasting Office content

Dreamweaver automatically converts material copied from Word and Excel into clean HTML. The procedure is truly transparent: Simply copy your content in either Word or Excel using the standard copy or cut commands, switch to Dreamweaver, and paste by choosing Edit

Copying and pasting Office content

Because Dreamweaver is actually converting material from one format to another, you may experience a short delay after pasting. If a great deal of conversion is needed—the more heavily the original content is formatted, the more conversion is required—Dreamweaver displays an alert to let you know that the operation might take some time and gives you the option to cancel.

Importing Office documents

Existing Word or Excel files can be imported directly into Dreamweaver in a single operation. Dreamweaver automatically converts the content from the Office format to HTML. To begin an import operation, choose File

Importing Office documents

The content is pasted according to the option chosen at import time. The available options are selected from a list at the bottom of the Import Word Document (see Figure 8-11) and Import Excel Document dialog boxes and echo those found in the Copy/Paste category of Preferences.

Select from the Formatting drop-down list.

Figure 8-11. Select from the Formatting drop-down list.

  • Text Only: Pastes completely unformatted text; even line breaks or paragraphs are removed.

  • Text With Structure: Pastes unstyled text while retaining structured elements such as lists, paragraphs, line breaks, and tables.

  • Text, Structure, Basic Formatting: Adds simple formatting, such as bold, italic, and underline, to structured text. If the text is copied from an HTML document, the pasted text retains any HTML text style tags, including <b>, <i>, <u>, <strong>, <em>, <abbr>, and <acronym>.

  • Text, Structure, Full Formatting: Pasted text keeps all structure and formatting. If the copied text retains inline CSS styles, Dreamweaver pastes them as well.

  • Clean Up Word Paragraph Spacing: Removes additional spaces between copied Word paragraphs; this option is available when either the Text With Structure or Text, Structure, Basic Formatting option is selected.

Excel documents are converted to tables with content formatted according to the options.

Dragging and dropping Word and Excel files

Not all Office documents are appropriate for converting to HTML. In some situations, it's best to leave the document in the original format and link to it from the Web page. Intranets—where access to Word or Excel is practically guaranteed and lengthy documents are the norm—are prime candidates for this type of design decision. Dreamweaver offers an easy way to make Office files Web accessible and gives you the option to use it as you see fit.

You've seen how a copy and paste operation from Word and/or Excel is relatively seamless. That's fine for material on the clipboard, but what about entire documents? Dreamweaver permits such Microsoft Office documents to be dragged and dropped right onto the page. What happens next for Windows users depends on the settings in Preferences. In the Office Copy/Paste category, you have two basic options: insert the content (formatted according to the standard options) or create a link to the document. On the Macintosh, a link is always created.

When an Office document is dragged onto the Web page (whether from the Files panel or the desktop), the Insert Document dialog box appears, as shown in Figure 8-12. If you opt to insert the file, Dreamweaver automatically converts the document according to the options selected. When you choose to create a link, a text link to the file is inserted.

Drag and drop Office files wherever you'd like the converted document or link to appear.

Figure 8-12. Drag and drop Office files wherever you'd like the converted document or link to appear.

Tip

Dreamweaver will remember the option chosen from one import operation to the other; these settings are independent of the choices made in the Copy/Paste category of Preferences.

Importing Word HTML

Microsoft Word has offered an option to save its documents as HTML since the release of Word 97. Unfortunately, Microsoft's version of HTML output is, at best, highly idiosyncratic. Although you could always open a Word HTML file in Dreamweaver, if you ever had to modify the page—which you almost always do—it took so long to find your way through the convoluted code that you were almost better off building the page from scratch. Fortunately, that's no longer the case with Dreamweaver.

Tip

Another reason to import an HTML file exported from Word, rather than just directly opening and editing it in Dreamweaver, is file size. Results vary, but importing a Word HTML document can reduce its size by half, or even more.

The capability to open and clean up Word HTML documents is a key workflow enhancement for Dreamweaver. Dreamweaver can successfully open and clean up files from Microsoft Word 97, Word 98, Word 2000, Word 2002, or Word 2003. You can even apply the current Code Format profile from Preferences so that the HTML is styled to look like native Dreamweaver code.

Naturally, before you can import a Word HTML file, you must create one. To export a document in HTML format in Word 97/98, you choose File

Importing Word HTML
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns="http://www.w3.org/TR/REC-html40">

Dreamweaver alters the preceding code to

<html>

If you accept the defaults, bringing a Word HTML file into Dreamweaver is pretty easy:

  1. Choose File Open. When the Select File dialog box opens, navigate and select the file that you exported from Word.

  2. Choose Commands

    Importing Word HTML
  3. Dreamweaver detects whether the HTML file was exported from Word 97/98 or Word 2000 or later and changes the interface options accordingly.

    Warning

    If Dreamweaver can't determine what version of Word generated the file, an alert appears. Although Dreamweaver still tries to clean up the code, it may not function correctly. The same alert appears if you inadvertently select a standard non-HTML Word document.

  4. Select options as desired and click OK to confirm the import operation. Dreamweaver cleans up the code according to the options you've selected; for large documents, you may have to wait a noticeable amount of time for this operation to complete. If the Show Log On Completion option is selected, Dreamweaver informs you of the modifications made.

For most purposes, accepting the defaults is the best way to quickly bring in your Word HTML files. However, because Web designers have a wide range of code requirements, Dreamweaver provides a full set of options for tailoring the Word-to-Dreamweaver transformation to your liking. Two different sets of options exist: one for documents saved from Word 97/98 and one for those saved from Word 2000 or newer. The different sets of options can be seen on the Detailed tab of the Clean Up Word HTML dialog box; the Basic tab is the same for both file types. Table 8-7 details the Basic tab options, the Word 97/98 options, and the Word 2000 or newer options.

Table 8-7. Import Word HTML Options

Option

Description

Basic

 

Remove all Word specific markup

Deletes all Word-specific tags, including Word XML, conditional tags, empty paragraphs, and margins in <style> tags.

Clean up CSS

Deletes Word-specific CSS code, including inline CSS styles where styles are nested, Microsoft Office (mso) designated styles, non-CSS style declarations, CSS style attributes from tables, and orphaned (unused) style definitions.

Clean up <font> tags

Deletes <font> tags that set the default body text to an absolute font size.

Fix invalidly nested tags

Deletes tags surrounding paragraph and block-level tags.

Set background color

Adds a background color to the page. Word normally doesn't supply one. The default added color is white (#ffffff). Colors can be entered as hexadecimal triplets with a leading hash mark or as valid color names, such as red.

Dreamweaver sets the background color by adding the bgcolor attribute to the <body> tag. If you do not have to support older browsers, you may instead wish to assign a background color using Cascading Style Sheets, described in Chapter 7.

Apply source formatting

Formats the imported code according to the guidelines of the current Code Format profile set in Preferences.

Show log on completion

Displays a dialog box that lists all alterations when the process is complete.

Detailed Options for Word 97/98

 

Remove Word specific markup

Enables the general clean-up of Word-inserted tags

Word meta and link tags from <head>

Specifically enables Dreamweaver to remove Word-specific <meta> and <link> tags from the <head> section of a document

Clean up <font> tags

Enables the general clean-up of <font> tags

Convert size [7-1] to

Specifies which tag, if any, is substituted for a <font size=n> tag. Options are

  • <h1> through <h6>

  • <font size=1> through <font size=7>

  • Default size

  • Don't change

Detailed Options for Word 2000 or newer

 

Remove Word specific markup

Enables the general clean-up of Word-inserted tags

XML from <html> tag

Deletes the Word-generated XML from the <html> tag

Word meta and link tags from <head>

Specifically enables Dreamweaver to remove Word-specific <meta> and <link> tags from the <head> section of a document

Word XML markup

Enables the general clean-up of Word-inserted XML tags

<![if...]><![endif]> conditional tags and their contents

Removes all conditional statements

Remove empty paragraphs and margins from styles

Deletes <p> tags without a closing </p>, empty <p></p> pairs, and styles tags including margin attributes—for example, style='margin-top:0in'

Clean up CSS

Enables the general clean-up of Word-inserted CSS tags

Remove inline CSS styles when possible

Deletes redundant information in nested styles

Remove any style attribute that starts with "mso"

Eliminates Microsoft Office (mso) specific attributes

Remove any non-CSS style declaration

Deletes nonstandard style declarations

Remove all CSS styles from table rows and cells

Eliminates style information from <table>, <tr>, and <td> tags

Remove all unused style definitions

Deletes any declared styles that are not referenced in the page

Styling Your Text

Initially, the Internet was intended to make scientific data widely accessible. Soon it became apparent that even raw data could benefit from being styled contextually without detracting from the Internet's openness and universality. Over the short history of HTML, text styles have become increasingly important, and the W3C has sought to keep a balance between substance and style.

Dreamweaver enables the Web designer to apply the most popular HTML styles directly through the program's menus and Property inspector. Less prevalent styles can be inserted through the integrated text editors or by hand. All the techniques covered in this section can be applied to dynamically inserted text.

Depicting various styles

HTML contains two types of style tags that are philosophically different from each other: logical tags and physical tags. The physical tags describe what text looks like; these include tags for bold, italic, and underlined text. HTML's logical styles denote what the text represents (such as code, a citation, or something typed from the keyboard) rather than what the text will actually look like. The eventual displayed appearance of logical styles is up to the viewer's browser.

Logical styles can be described as structural. They are useful when you are working with documents from different sources—reports from different research laboratories around the country, for instance—and you want a certain conformity of style. If you are trying to achieve a particular look using logical styles, you should consider using the Cascading Style Sheets feature instead of, or in addition to, logical styles. You can apply logical style tags and then use Cascading Style Sheets to define how that style will look when viewed in a browser.

Note

The styles that can be applied through regular HTML are just the tip of the iceberg compared to the possibilities available using Cascading Style Sheets. For details about using this feature, see Chapter 7.

Whereas logical styles are utilitarian, physical styles such as boldface and italic are decorative or presentational. With the advent of Cascading Style Sheets, use of the physical style tags is no longer the preferred method of styling text. However, physical tags are still supported and are still very widely used. Even with Cascading Style Sheets, both physical and logical styles have their uses in material published on today's Web. In Dreamweaver, logical and physical style tags can be accessed by choosing Text

Depicting various styles

Note

You can also add the most commonly used styles—bold, italic, strong, and emphasis—by clicking the appropriate button in the Text category of the Insert bar.

Figure 8-13 compares how styles are rendered in Dreamweaver, Internet Explorer 7.0, and Mozilla Firefox. Although the various renderings are mostly the same, notice the subtle difference between how the Keyboard style is rendered in Dreamweaver (far left) and in either browser. The various styles may be rendered quite a bit differently in other browsers and other browser versions.

In this comparison chart, the various renderings of style tags are from Dreamweaver, Mozilla Firefox, and Internet Explorer 7.0 (from left to right, respectively).

Figure 8-13. In this comparison chart, the various renderings of style tags are from Dreamweaver, Mozilla Firefox, and Internet Explorer 7.0 (from left to right, respectively).

Two of the physical style tags—bold and italic—are controlled by a Preferences setting. Although you can use the <b> and <i> tags to style text, it is considered better practice to use the equivalent logical tags, <strong> and <em>. Dreamweaver enables you to specify which tags to use via the Use <strong> And <em> In Place Of <b> And <i> option in the General category of Preferences. If this option is checked (the default), <strong> and <em> tags are used to code bold or italic text, respectively; if the option is clear, <b> and <i> tags are used.

To actually apply bold or italic formatting using either the logical or physical tags, select the text and then click the Bold or Italic button on the Text Property inspector, or use the keyboard shortcuts (Ctrl+B [Command+B] and Ctrl+I [Command+I], respectively). Buttons for bold, italic, strong, and emphasis are also available in the Text category of the Insert bar. If the General Preference setting (discussed previously) is set, then the Bold button on the Insert bar does the same thing as the Strong button, and the Italic button inserts the same code as the Emphasis button.

Warning

One physical style, the underline tag, <u>, is available only through the Text

In this comparison chart, the various renderings of style tags are from Dreamweaver, Mozilla Firefox, and Internet Explorer 7.0 (from left to right, respectively).

Both physical and logical style tags are described in Table 8-8.

Table 8-8. Text Style Tags

Style

Tag

Description

Bold

<b>

Text is rendered with a bold style.

Italic

<i>

Text is rendered with an italic style.

Underline

<u>

Text is rendered underlined.

Strikethrough

<s>

Used primarily in edited documents to depict edited text. Usually rendered with a line through the text.

Teletype

<tt>

Used to represent an old-style typewriter. Rendered in a monospace font such as Courier.

Emphasis

<em>

Used to accentuate certain words relative to the surrounding text. Most often rendered in italic.

Strong

<strong>

Used to strongly accentuate certain words relative to the surrounding text. Most often rendered in boldface.

Code

<code>

Used to depict programming code, usually in a monospace font.

Variable

<var>

Used to mark variables in programming code. Most often displayed in italic.

Sample

<samp>

Used to display characters in a literal sequence, usually in a monospace font.

Keyboard

<kbd>

Used to indicate what the user should input. Often shown in a monospace font, sometimes in boldface.

Citation

<cite>

Used to mark citations, references, and titles. Most often displayed in italic.

Definition

<dfn>

Used to denote the first, defining instance of a term. Usually displayed in italic.

Deleted

<del>

Used to denote deleted text, to aid in document authoring and editing. You can often find these tags in documents imported from Word HTML files that used the Track Changes feature. Although not fully supported in some browser versions, this style is typically depicted as a line through the text.

Inserted

<ins>

Used to denote inserted text. Like the Deleted style, this is used during the authoring process to keep track of changes. You can often find these tags in documents imported from Word HTML files that used the Track Changes feature. The style is usually depicted as underlined text.

Using the <address> tag

Currently, Dreamweaver does not support one useful style tag: the <address> tag. Rendered as italic text by browsers, the <address>...</address> tag pair often marks the signature and e-mail address of a Web page's creator.

Note

An easy way to do this in Dreamweaver is to use the Quick Tag Editor. Select your text and then press Ctrl+T (Command+T) to automatically enter Wrap Tag mode. If Tag Hints is enabled, all you have to do is start typing address, and press Enter (Return) twice to accept the hint and confirm the tag. In Code view and the Code inspector, the <address>...</address> tag pair is also available as a Code Hint.

If you're applying the <address> tag to multiple lines, use <br> tags to form line breaks. The following example shows the proper use of the <address> tags:

<address><p>The President<br>
 1600 Pennsylvania Avenue NW<br>
 Washington, DC 20500</p></address>

This code is shown on a Web browser as follows:

  • The President

  • 1600 Pennsylvania Avenue NW

  • Washington, DC 20500

Tip

To remove a standard style, highlight the styled text, choose Text

Using the <address> tag

Adding abbreviations and acronyms

Two other tags worth noting designate abbreviations, <abbr>...</abbr>, and acronyms, <acronym>...</acronym>. The abbreviation or acronym is enclosed within the tag pair. Both tags include a title attribute, which is used to specify the full text of the abbreviation or acronym. The following code shows examples of both tags:

<abbr title="Incorporated">Inc.</abbr>
<acronym title="Object-oriented Programming">OOP</acronym>

The <abbr> and <acronym> tags are relatively new and are not yet widely used. These tags are not intended to actually change the visual style of the text in a browser, but instead they enable programs that process the document to clearly identify acronyms and abbreviations. For example, in the future, words marked as abbreviations could allow non-visual browsers to read the expanded word, rather than sounding out the abbreviation. If designated as an abbreviation, the letters PA could be read as Pennsylvania rather than as the word pa. In the future, this tag could also be used to provide alternate text for search engines, spell checkers, and translation programs.

In Dreamweaver, you can insert acronyms or abbreviations by clicking the Acronym or Abbreviation button on the Text category of the Insert bar. You can also choose the appropriate command from the Insert

Adding abbreviations and acronyms

Modifying Text Format

As a Web designer, you easily spend at least as much time adjusting your text as you do getting it into your Web pages. Luckily, Dreamweaver puts most of the tools you need for this task right at your fingertips. Many of the text-formatting options are available through the Text Property inspector or the Tag inspector, whether you're styling your text in CSS or HTML <font> tags.

On the Web today, designers have largely moved to using Cascading Style Sheets and away from hard-coding text with <font> and other tags. Both 4.0+ versions of the major Web browsers support Cascading Style Sheets to some extent, and Internet Explorer has had some support since version 3.0. Text formatting enjoys the most widespread browser support of all the CSS rules.

Although CSS is now the preferred method of styling text—as well as the rest of the page—you may still encounter <font> tags in legacy pages. Dreamweaver allows you to work in both styles: To switch from the default CSS style properties, choose Edit

Modifying Text Format

Note

Refer to Chapter 7 if you're new to CSS and looking for a little background on how to create and apply styles.

Adjusting font size

Whether you're using CSS or <font> tags to format your text, you can alter its size in a variety of ways. Both methods allow you to specify text size in either an absolute or a relative measurement. You can also size any amount of text, from a single character to an entire page, with both techniques.

Sizing with CSS

The best-practice route for setting font size with CSS is to apply an existing style—declared either in an internal or external style sheet—to a tag or selection of text. However, you can also select a value from the Size field of the Property inspector as shown in Figure 8-14. If no style has been previously attached to the selection, Dreamweaver automatically creates an internal style named styleN where N is an incremented number. For example, the first style created in this fashion is named style1 and the second style2, and so on. After the automatically generated style is created, you can apply it to other selections.

If the text size you want is not listed, change it in the Size field.

Figure 8-14. If the text size you want is not listed, change it in the Size field.

In CSS, the aptly named font-size property controls the size of the text. When declared in a selector, font-size is used like this

In CSS, the aptly named font-size property controls the size of the text. When declared in a selector, font-size is used like this

h1 { font-size: 36px; }

or like this

#mainsidebar { font-size: 1.2em; }

or this

.legal { font-size: xx-small; }

As you can see, the font-size value may be a precise value (36px), a percentage (1.2em), or an absolute-size keyword (xx-small). In addition to pixels—abbreviated as px—CSS supports other measurement systems: points (pt), inches (in), centimeters (cm), millimeters (mm), and picas (pc).

Tip

Many designers advocate using pixel measurements as a way to achieve a consistent look and feel across browsers.

CSS provides three different relative-based measurement systems for sizing text: em, ex, and percentage (%). All three assume that a specific font size has been declared for the parent or containing tag; if no specific font size is defined, the default setting of the parent's font size is used for comparison. A font-size of 1em is equivalent to whatever the containing tag's font-size is; for example, if the containing <div> tag has a font-size of 20px, a selector with a font-size set to 1.2em is rendered as 24px—because 20 times 1.2 is equal to 24. Percentage measurements work exactly the same way as em measurements; 1.2% is the same as 1.2em.

The ex measurement, however, is quite different. Short for x-height, the ex measurement system is based on the height of a lowercase x in the current font. Character heights vary quite substantially from one font to another: At 72 pixels, an x in Times is about 32px high whereas in Arial, it's almost 40px. Because of the widely varying differences, the ex measurement system is rarely used.

There are seven font-size keywords, which correspond to the HTML size attribute values 1–7. The two are similar in that both rely on the browser for final size interpretation, and the sizes for both are relative to each other, as shown in Figure 8-15.

CSS specifications include two additional keywords: larger and smaller. These relative-based keywords are obviously intended to be used in relation to the current font size. For example, in a <div> where the font-size value is 10px, any text whose font-size value is larger would be rendered at about 12px, whereas a smaller value would display text at 8px.

In Dreamweaver, the font-size property is set in the Type category of the CSS Rule Definition dialog box or in the Relevant CSS category of the Tag inspector.

Applying <font> sizes

When you work with <font> tags, the six HTML heading types enable you to assign relative sizes to a line or to an entire paragraph. In addition, HTML gives you a finer degree of control through the size attribute of the font tag. In contrast to publishing or CSS environments, both traditional and desktop, font size is not specified in HTML with points. Rather, the <font> tag enables you to choose one of seven different explicit sizes that the browser can render (absolute sizing), or you can select one relative to the page's basic font. Figure 8-16 shows the default absolute and relative sizes, compared to a more page-designer–friendly point chart (accomplished with Dreamweaver's Cascading Style Sheets features).

The font-size property keywords parallel the <font> tag's size attribute values.

Figure 8-15. The font-size property keywords parallel the <font> tag's size attribute values.

This chart shows the relationships between the various font sizes in an HTML browser as compared to real-world point sizes.

Figure 8-16. This chart shows the relationships between the various font sizes in an HTML browser as compared to real-world point sizes.

Which way should you go—absolute or relative? Some designers think that relative sizing gives them more options. As you can see by the chart in Figure 8-16, browsers are limited to displaying seven different sizes no matter what—unless you're using Cascading Style Sheets. Relative sizing does give you additional flexibility because you can resize all the fonts in an entire Web page with one command. Absolute sizes, however, are more straightforward to use and can be coded in Dreamweaver without any additional HTML programming. Once again, it's the designer's choice.

Absolute size

You can assign an absolute font size through either the Property inspector or the menus. In both cases, you choose a value, 1 (smallest) through 7 (largest), to which you want to resize your text; you might note that this order is the reverse of the heading sizes, which range from H1 to H6, largest to smallest.

To use the Property inspector to pick an absolute font size, follow these steps:

  1. Select your text.

  2. In the Property inspector, open the Size drop-down list of options. If the Size drop-down list is not visible on the Text Property inspector, click the Toggle CSS/HTML Mode icon, located to the right of the Format drop-down list.

  3. Choose a value from 1 to 7.

To pick an absolute font size from the menu, follow these steps:

  1. Select your text.

  2. Choose Text

    Absolute size

Note

You can also click the Font Tag Editor button in the Text category of the Insert bar to adjust font size, color, and so on.

Relative size

To what exactly are relative font sizes relative? The default font size, of course. The advantage of relative font sizes is that you can alter a Web page's default font size with one command, the <basefont> tag. The tag takes the following form

<basefont size=" value ">

where value is a number from 1 to 7. The <basefont> tag is usually placed immediately following the opening <body> tag. Dreamweaver does not support previewing the results of altering the <basefont> tag, and the tag has to be entered by hand or through the external editor.

You can distinguish a relative font size from an absolute font size by the plus or minus sign that precedes the value. The relative sizes are plus or minus the current <basefont> size. Thus, a <font size= "+1"> is normally rendered with a size 4 font because the default <basefont> is 3. If you include the following line in your Web page:

<basefont size="5">

text marked with a <font size="+1"> is displayed with a size 6 font. Because browsers display only seven different size fonts with a <basefont size="5"> setting—unless you're using Cascading Style Sheets—any relative size over <font size="+2"> won't display differently when previewed in a browser.

Warning

If you change the basefont value, some browsers do not correctly handle relative font sizes for text within tables. In this case, you use absolute sizes. Also, Dreamweaver itself does not recognize the <basefont> tag; so to accurately see a page that uses relative sizes and the <basefont> tag, view it in a browser.

Relative font sizes can also be selected from either the Property inspector or the menus. To use the Property inspector to pick a relative font size, follow these steps:

  1. Select your text or position the cursor where you want the new text size to begin.

  2. In the Property inspector, open the Size drop-down list of options. If the Size drop-down list is not visible on the Text Property inspector, click the Toggle CSS/HTML Mode icon, located to the right of the Format drop-down list.

  3. To increase the size of your text, choose a value from +1 through +7. To decrease the size of your text, choose a value from −1 to −7.

To pick a relative font size from the menus, follow these steps:

  1. Select your text or position the cursor where you want the new text size to begin.

  2. To increase the size of your text, choose Text

    Relative size

Adding font color

Unless you assign a color to text on your Web page, the browser uses its own default, typically black. To change the font color for the entire page, choose Modify

Adding font color

You can also apply color to individual headings, words, or paragraphs that you have selected in Dreamweaver. As with text size, when working with CSS the best way to set a color for a selected tag or text range is to apply an existing style that includes the desired color. Font color is defined through the Type category of the CSS Rule Definition dialog or the color attribute of the Tag inspector's Relevant CSS category.

Whether working in CSS or <font> tags, text color is expressed in either a hexadecimal color number or a color name. The hexadecimal color number is based on the color's red-green-blue value and is written like this:

#FFFFFF

The preceding represents the color white. You can also use standard color names instead of the hexadecimal color numbers. A sample color code line follows:

I'm <font color="green">GREEN</font> with envy.

In CSS, the same color attribute is used, but written somewhat differently:

.envy {color:green;}

Again, you have several ways to add color to your text in Dreamweaver. Click the color box in the Property inspector to display the color picker, displaying a limited palette of colors. Clicking the System Color Picker button in the color picker enables you to choose from a full-spectrum Color dialog box.

Warning

If you want to apply the same color that you've already used elsewhere in your site to your text, you can display the Color category on the Assets panel (choose Window

Adding font color

If you approach your coloring task via the menus, the Text

Adding font color
  1. Select the text you want to color, or position the cursor where you want the new text color to begin. If you're using CSS, a <span> tag is applied with auto-generated style (style1).

  2. From the Property inspector, you can

    • Type a hexadecimal color number directly into the Text Color text field

    • Type a color name directly into the Text Color text field

    • Select the color box to open the color picker

  3. If you chose to type a color name or number directly into the Text Color text field, press Tab or click in the Document window to see the color applied.

  4. If you clicked the color box, select your color from the palette of colors available. As you move your pointer over the color swatches, Dreamweaver displays the color and the color's hexadecimal number above.

  5. For a wider color selection, open the Color dialog box by selecting the System Color Picker icon in the upper-right corner of the color picker.

To access the full-spectrum color picker in Windows, follow these steps:

  1. Select your text or position your cursor where you want the new text color to begin.

  2. Choose Text

    Adding font color
    Use the Color (Colors) dialog box to choose a color for your font outside of the browser-safe palette.

    Figure 8-17. Use the Color (Colors) dialog box to choose a color for your font outside of the browser-safe palette.

  3. Select one of the 48 preset standard colors from the color swatches on the left of the Color dialog box, or use either of the following methods:

    • Select a color by moving the Hue/Saturation pointer and the Luminance pointer.

    • Enter decimal values directly into either the Red, Green, and Blue boxes or the Hue, Saturation, and Luminance boxes.

  4. If you create a custom color, you can add it to your palette by clicking Add To Custom Colors. You can add up to 16 custom colors.

  5. Click OK when you are finished.

Warning

When you add a custom color to your palette in Windows, the new color swatch goes into the currently selected swatch or, if no swatch is selected, the next available swatch. Make sure you have selected an empty or replaceable swatch before clicking the Add To Custom Colors button. To clear the custom colors, first set the palette to white by bringing the Luminance slider all the way to the top. Then, click the Add To Custom Colors button until all the color swatch text fields are empty.

To access the full-spectrum color picker in Macintosh systems (see Figure 8-17), follow these steps:

  1. Select the text or position your cursor where you want the new text color to begin.

  2. Choose Text

    Dreamweaver's Color Pickers
  3. In the Macintosh color picker, the list of available pickers is displayed across the top of the dialog like a toolbar, and each particular interface's options are shown below as they are selected. Choose a color picker, by clicking on its icon in the top toolbar, and create the color you want in the rest of the dialog below. (The number and type of color pickers vary from system to system, depending on the version of the operating system and whether you've added any third-party color pickers.)

  4. When you've found the desired color, click OK.

Assigning a specific font

Along with size and color, you can also specify the typeface in which you want particular text to be rendered. Because of HTML's unique way of handling fonts, Dreamweaver uses a special method for choosing font names for a range of selected text. Before you learn how to change a typeface in Dreamweaver, you should more fully examine how fonts in HTML work.

About HTML fonts

Page layout designers can incorporate as many different fonts as available to their own systems. Web layout designers, on the other hand, can use only those fonts on their viewers' systems. If you designate a paragraph to be in Bodoni Bold Condensed, for instance, and put it on the Web, the paragraph is displayed with that font only if that exact font is on the user's system. Otherwise, the browser uses the default system font, which is often Times or Times New Roman.

Fonts are specified with the <font> tag, aided by the face attribute. Because a designer can never be certain which fonts are on visitors' computers, HTML enables you to offer a number of options to the browser, as follows:

<font face="Arial, Helvetica, sans-serif">Swiss Maid Foundry</font>

The browser encountering the preceding tag first looks for the Arial font to render the enclosed text. If Arial isn't there, the browser looks for the next font in the list, which in this case is Helvetica. If it fails to find any of the specified fonts listed, the browser uses whichever font has been assigned to the category for the font—sans serif in this case.

Selecting a font

The process for assigning a font name to a range of text is similar to that of assigning a font size or color. Instead of selecting one font name, however, you're usually selecting one font series. That series could contain three or more fonts as previously explained. Font series are chosen from the Font list in the CSS Rule Definition dialog's Text category, the Property inspector, or through a menu item. Dreamweaver enables you to assign any font on your system—or even any font you can name—to a font series, as covered in the section "Editing the Font List," later in this chapter.

To assign a specific font series to your text, follow these steps:

  1. Select the text or position your cursor where you want the new text font to begin.

  2. From the Property inspector, open the drop-down list of font names. You can also display the list of fonts by choosing Text

    Selecting a font
  3. Select a font from the Font List. To return to the system font, choose Default Font from the list.

It's also possible to enter the font name or font series directly in the Property inspector's Font drop-down list box.

Editing the font list

With the Edit Font List dialog box, Dreamweaver gives you a point-and-click interface for building your font lists. After the Edit Font List dialog box is open, you can delete an existing font series, add a new one, or change the order of the list so your favorite ones are on top. Figure 8-18 shows the sections of the Edit Font List dialog box: the current Font List, the Available Fonts on your system, and the Chosen Fonts. The Chosen Fonts are the individual fonts that you've selected to be incorporated into a font series.

Dreamweaver's Edit Font List dialog box gives you considerable control over the fonts that you can add to your Web page.

Figure 8-18. Dreamweaver's Edit Font List dialog box gives you considerable control over the fonts that you can add to your Web page.

Follow these steps to construct a new font series and add it to the font list:

  1. To open the Edit Font List dialog box, either expand the Font drop-down list in the Property inspector and select Edit Font List, or choose Text

    Dreamweaver's Edit Font List dialog box gives you considerable control over the fonts that you can add to your Web page.
  2. If the Chosen Fonts box is not empty, clear the Chosen Fonts box by clicking the Add (+) button at the top of the dialog box. You can also scroll down to the bottom of the current Font List and select (Add fonts in list below).

  3. Select a font from the Available Fonts list. The font categories, such as sans serif and cursive, appear at the end of the available fonts list.

  4. Click the << button to transfer the selected font to the Chosen Fonts list.

  5. To remove a font you no longer want or have chosen in error, highlight it in the Chosen Fonts list and click the >> button.

  6. Repeat steps 3 through 5 until the Chosen Fonts list contains the alternative fonts you want.

  7. If you want to add another, separate font series, repeat steps 2 through 6.

  8. Click OK when you are finished adding fonts.

To change the order in which font series are listed in the Font List, follow these steps:

  1. In the Edit Font List dialog box, select the font series that you want to move.

  2. If you want to move the series higher up the list, click the up arrow button at the top right of the Font List. If you want to move the series lower down the list, click the down arrow button.

To remove a font series from the current Font List, highlight it and click the Remove (–) button at the top left of the list.

Remember that the fonts must be on your system to make them a part of your font list. To add a font unavailable on your computer, type the name of the font into the text field below the Available Fonts list and press Enter (Return).

Aligning text

You can easily align text in Dreamweaver, just as you can in a traditional word processing program. HTML supports the alignment of text to the left or right margin, or in the center of the browser window. Another option, called Justify, causes text to be flush against both left and right margins, creating a block-like appearance. The Justify value is supported in browsers 4.0 and later on Windows platforms.

Like a word processing program, Dreamweaver aligns text one paragraph at a time. You can't left-align one word, center the next, and then right-align the third word in the same paragraph.

To align text, use one of several methods: a CSS style, a menu command, the Property inspector, or a keyboard shortcut. When declaring an alignment in CSS, select a value from the Text Align list found in the Block category of the CSS Rule Definition dialog box.

To use the menus, choose Text

Aligning text
The Text Property inspector includes buttons to left align, center, right align, and justify your text.

Figure 8-19. The Text Property inspector includes buttons to left align, center, right align, and justify your text.

The alignment keyboard shortcuts are as follows:

Alignment

Windows shortcut

Mac shortcut

Left

Ctrl+Alt+Shift+L

Command+Option+Shift+L

Center

Ctrl+Alt+Shift+C

Command+Option+Shift+C

Right

Ctrl+Alt+Shift+R

Command+Option+Shift+R

Justify

Ctrl+Alt+Shift+J

Command+Option+Shift+J

Indenting entire paragraphs

HTML offers a tag that enables you to indent whole paragraphs, such as inset quotations or name-and-address blocks. Not too surprising, the tag used is called the <blockquote> tag. Dreamweaver gives you instant access to the <blockquote> tag through the Indent and Outdent buttons located on the Text Property inspector, as shown in Figure 8-20.

Indent and adjust the indentation of paragraphs and blocks of text by using the Indent and the Outdent buttons.

Figure 8-20. Indent and adjust the indentation of paragraphs and blocks of text by using the Indent and the Outdent buttons.

To indent one or more paragraphs, select them and click the Indent button in the Property inspector. Paragraphs can be indented multiple times; each time you click the Indent button, another <blockquote>...</blockquote> tag pair is added. Note that you can't control how much space a single <blockquote> indents a paragraph—that characteristic is determined by the browser.

You also have the option of indenting your paragraphs through the menus by choosing Text

Indent and adjust the indentation of paragraphs and blocks of text by using the Indent and the Outdent buttons.

If you find that you have over-indented, use the Outdent button, also located on the Property inspector. The Outdent button has no effect if your text is already at the left edge. Alternatively, you can choose Text

Indent and adjust the indentation of paragraphs and blocks of text by using the Indent and the Outdent buttons.

Tip

You can tell how many <blockquote> tags are being used to create a particular look by placing your cursor in the text and looking at the Tag Selector.

Incorporating Dates

With the Web constantly changing, keeping track of when information is updated is important. Dreamweaver includes a command that enables you to insert today's date in your page, in almost any format imaginable. Moreover, you can set the inserted date to be automatically updated every time the page is saved. This means that every time you make a modification to a page and save it, the current date is added.

The Insert Date command uses your system clock to get the current date. In addition, you can elect to add a day name (for example, Thursday) and the time to the basic date information. After the date text is inserted, it can be formatted like any other text—adding color or a specific font type or changing the date's size.

To insert the current date, follow these steps:

  1. Choose Insert

    Incorporating Dates
    Keep track of when a file is updated by using the Date command.

    Figure 8-21. Keep track of when a file is updated by using the Date command.

  2. If desired, select a Day Format to include in the date from the drop-down list. The options are as follows:

    [No Day]

    Thu

    Thursday,

    thu,

    Thursday

    thu

    Thu

     
  3. Select the desired date format from the drop-down list. The example formats are as follows:

    March 7, 1974

    7/03/74

    07-Mar-1974

    07.03.1974

    7-mar-74

    07.03.74

    03/07/1974

    7-03-1974

    3/7/74

    7 March, 1974

    1974-03-07

    74-03-07

    7/3/74

     

    Tip

    If you are creating Web pages for the global market, consider using the format designated by the 1974-03-07 example. This year-month-day format is an ISO (International Organization for Standardization) standard and is computer-sortable.

  4. Select the desired time format, if any, from the drop-down list. The example formats are as follows:

    • [No Time]

    • 10:18 PM

    • 22:18

  5. If you want the date modified to include the current date every time the file is saved, select the Update Automatically On Save option.

  6. Click OK when you're finished.

Tip

It's easy to format an inserted date when the Update Automatically On Save option is not selected—it's just plain text, and the formatting can be added easily through the Text Property inspector. However, if the date is to be automatically updated, it's inserted as a special Adobe data type with its own Property inspector. You can style it, however, by applying a CSS style.

If your date object includes the Automatic Update option, you can modify the format. Select the date and, in the Property inspector, click the Edit Date Format button. The Edit Date Format dialog box opens, which is nearly identical to the Insert Date dialog box, except the Update Automatically On Save option is not available.

Commenting Your Code

How do you know when to begin inserting comments into your HTML code? You know the first time you go back to an earlier Web page, look at the code, and say, "What on earth was I thinking?" You should plan ahead and develop the habit of commenting your code now.

Browsers run fine without your comments, but for any continued development—of the Web page or of yourself as a Webmaster—commenting your code is extremely beneficial. Sometimes, as in a corporate setting, Web pages are co-developed by teams of designers and programmers. In this situation, commenting your code may not just be a good idea; it may be required. An HTML comment looks like the following:

<!-- Created by Hummer Associates, Inc. -->

You're not restricted to any particular line length or number of lines for comments. The text included between the opening of the comment, <!--, and the closing, -->, can span regular paragraphs or HTML code. In fact, one of the most common uses for comments during the testing and debugging phase of page design is to comment out sections of code as a means of tracking down an elusive bug.

To insert a comment in Dreamweaver, first place your cursor in either the Document window or the Code inspector where you want the comment to appear. Then click the Comment button in the Common category of the Insert bar. This sequence opens the Comment dialog box, where you can type the desired text; click OK when you've finished. Figure 8-22 shows a completed comment in Design and Code views, with the corresponding Property inspector open.

Comments are extremely useful for inserting into the code information not visible on the rendered Web page.

Figure 8-22. Comments are extremely useful for inserting into the code information not visible on the rendered Web page.

By default, Dreamweaver inserts a Comment symbol in the Document window. You can hide the Comment symbol by choosing Edit

Comments are extremely useful for inserting into the code information not visible on the rendered Web page.

You can also add a comment using the Snippets panel. To use this method, choose Window

Comments are extremely useful for inserting into the code information not visible on the rendered Web page.

Tip

The Snippets panel is really good for commenting out a section of code or text already on the page. With your code or text selected, choose the desired comment style and drop it right on your selection. Presto, chango—instant comments!

To edit a comment, double-click the Comment symbol to display the current comment in the Property inspector. A comment can be moved or duplicated by selecting its symbol and then using the Cut, Copy, and Paste commands under the Edit menu. You can also right-click (Control+click) the Comment symbol to display the context menu. Finally, you can click and drag Comment symbols to move the corresponding comment to a new location.

Summary

Learning to manipulate text is an essential design skill for creating Web pages. Dreamweaver gives you all the tools you need to insert and modify the full range of HTML text quickly and easily. As you work with text on your Web pages, keep these points in mind:

  • HTML headings are available in six different sizes: <h1> through <h6>. Headings are used primarily as headlines and subheads to separate divisions of the Web page.

  • Blocks of text are formatted with the paragraph tag <p>. Each paragraph is separated from the other paragraphs by a line of whitespace above and below. Use the line break tag, <br>, to make lines appear directly above or below one another.

  • Dreamweaver offers a full complement of text-editing tools—everything from Cut and Paste to Find and Replace. Dreamweaver's separate Design and Code views make short work of switching between text and code.

  • Dreamweaver's Find and Replace feature goes a long way toward automating your work on the current page as well as throughout the Web site. Both content and code can be searched in a basic or very advanced fashion.

  • Where possible, text in HTML is formatted according to its meaning. Dreamweaver applies the styles selected through the Text

    Summary
  • You can format Web page text much as you can text in a word processing program. Within certain limitations, you can select a font's size and color, as well as the font face.

  • Dreamweaver's HTML Styles feature enables you to format your text consistently and quickly.

  • HTML comments are a useful (and often requisite) vehicle, which remains unseen by the casual viewer, for embedding information into a Web page. Comments can annotate program code or insert copyright information.

In the next chapter, you learn how to insert and work with graphics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset