Macromedia Dreamweaver MX 2004 Demystified

[ LiB ]

Tables themselves aren't difficult to understand, but they're constructed from many bits and pieces, and working with them in Dreamweaver and in the browser is a complex process.

Tables in the Browser

In HTML, tables are created with the table tag. Each table consists of a number of rows, specified by tr (table row) tags. Each row consists of cells , specified by td (table data) or th (table header) tags. Nowhere is the number of columns specified; that's determined by the number of cells in the rows. The basic code framework for a two-row, two-column table looks like this:

<table> <tr> <th>[header cell contents here]</th> <th>[header cell contents here]</th> </tr> <tr> <td>[cell contents here]</td> <td>[cell contents here]</td> </tr> </table>

This table includes one row of header cells and one of regular data cells. Note that none of the tags involved requires any attributes. Various optional attributes determine how the table will look and behave, including dimensions, border, treatment of cell contents, and so on. Table 8.1 lists the most commonly used attributes and what they're for. Many more attributes are possible, some included in the HTML specification and others for use by particular browsers. (Check the Dreamweaver Reference panel for a more comprehensive list.)

Table 8.1. Commonly Assigned Attributes Used with Tables

Attribute Name

Description

ApplyTo

Values

name id

Used for identification.

table , tr , td , th

Text string

width (height)

Table or cell dimensions. (Only width is part of the HTML specification, although height may be recognized by browsers.)

table , td , th

Number (pixels) or percent value

border

Whether the element has a border surrounding it.

table , td , th

Number

cellpadding

Gutter space within each cell, between cell edge and contents.

table

Number (pixels)

cellspacing

Space between each cell.

table

Number (pixels)

bgcolor

Background color of the element.

table , tr , td , th

Color, identified by number or name

background

Background image for the element.

table , tr , td , th

URL of an image file

align

Horizontal alignment of cell contents

table , tr , td , th

left , center , right

valign

Vertical alignment of cell contents.

tr , td , th

top , middle , bottom , baseline

colspan , rowspan

How many columns or rows the cell spansthe HTML mechanism for merging cells.

tr , th , td

Number (of columns or rows)

Tables in HTML were originally developed for use in displaying tabular data (see Figure 8.1), but web designers adopted them for use in page layout (see Figure 8.2). With the advent of CSS positioning, tables should be reverting to their original use. However, inconsistent browser support of CSS means that, so far, tables are still the safest best for page layout.

Figure 8.1. A table used for displaying tabular data in a web page.

Figure 8.2. A borderless table used for setting the layout of a web page.

Tables in Dreamweaver

Because tables are so important, Dreamweaver has a variety of tools and commands for working with them. Some are safer to use than others, and some are more intuitive than others. No matter what your working strategy is, you'll undoubtedly find something in here that you like.

Table Interface Choices

Of course, your first decision, as with anything in Dreamweaver, is whether you want to work with tables in Design view or Code view. But even within the Design view environment, you have choices. What should the table-making interface be like? What visual aids do you need?

Choosing a Table Mode

To choose a table mode, go to the View menu and choose from the options in the Table Mode submenu; or, in the Layout Insert bar, choose one of the three Table Mode buttons (as shown in Figures 8.38.5). In either case, you have three choices:

Table-Viewing Aids

Whether you're working in Standard or Expanded Tables mode, you have a few extra bits of visual aids that you can call on in the Design view interface:

Inserting Tables

To insert a table (unless you're working in Layout mode), use the Table object in the Layout Insert bar, or choose Insert > Table. Both of these methods open the Insert Table dialog box (see Figure 8.8). In the dialog box, specify the basic structure of your table and click OK to insert the table. Note that, other than specifying rows and columns, you don't have to specify values for any table characteristics while inserting. Also, all table structure and attributes can be edited later through the Property Inspector, so nothing is set in stone here.

Figure 8.8. Inserting a table.

For more on table accessibility attributes, see the section "Making Your Tables Accessible," later in this chapter.

The Table object always remembers the values you used the last time you inserted a table, so you probably won't have to deal with every item every time you create another table.

Have you ever looked at the code for a brand-new table and seen that each cell contains &nbsp;? What's that doing in there?

This is the HTML entity for a nonbreaking space. Some browsers don't properly display empty table cells, so Dreamweaver doesn't let you create them. Every time it sees an empty cell, it tucks a nonbreaking space in there. As soon as you put content in the cell, Dreamweaver removes the space. Delete the content, and the space is back! That's a nice bit of housekeeping taken care of for you.

Selecting Tables

Working with tables means selecting tables, rows, columns, and cellsand that's not always easy. The more you're familiar with the different selecting options and techniques, the more efficiently you'll work with tables. The two main techniques for selecting are by clicking and dragging various items inside the Document window, and by using the Tag Selector. You can also use keyboard shortcuts to navigate around the table and select items within it. For the most part, use the method you like best; sometimes one method works better in a given situation than another, though, so it's a good idea to be familiar with all of them.

Selecting from Within the Document Window

Some people are just born clickers-and-draggers. Clicking something in the Document window is the most intuitive way to select things for most people. With tables, though, there are so many possibilities!

Selecting with the Tag Selector

The Tag Selector can be your best friend when you're working with tables. First, you can use it as an indicator of where you are in your table's structure. Click inside any cell, or select any cell or row, and the Tag Selector displays the structure of the table around you (see Figure 8.10). Plus, of course, the Tag Selector is great for selecting tags. Just click inside any cell to place the insertion point there; then click on the td tag in the Tag Selector to select the cell, the tr tag to select the row that encloses that cell, or the table tag to select the entire table. The Tag Selector is your author's favorite method of selecting tables.

Figure 8.10. Using the Tag Selector to select a table element.

The Tag Selector is less useful for selecting multiple elements or for selecting table columns (because columns have no tag associated with them).

Keyboard Navigation and Selection

Dreamweaver has made working with HTML tables very similar to working with tables in word-processing programs or spreadsheets, so your favorite keyboard-access methods from those other programs will work here, too.

To move from cell to cell, press Tab (move forward) or Shift+Tab (move backward). Or, use the arrow keys to move through the contents of your cells and to move from cell to cell.

To select a cell from the keyboard, make sure the insertion point is inside that cell and press Ctrl/Cmd+[ (that's the opening square bracket key). This is the keyboard shortcut for Edit > Select Parent Tag. When you have the first cell selected, you can select adjacent cells by pressing the arrow keys. Or, you can press Ctrl/Cmd+[ again to select the row containing that cell, and Ctrl/Cmd+[ again to select the entire table.

Setting Table Properties

Like just about everything in Design view, tables and cells have associated Property Inspectors to help you work with them. Select a table, and the Table Property Inspector appears (see Figure 8.11). Place the cursor inside any cell, and the lower half of the Property Inspector shows table cell properties (see Figure 8.12). Although table rows have no associated inspector, when all cells in a row are selected, the Property Inspector shows row properties in the cell property area.

Figure 8.11. The Table Property Inspector.

Figure 8.12. The Property Inspector showing table cell (or row) properties.

Most of the properties shown in these two Inspectors match up to those shown in Table 8.1. Others can be looked up in the Reference panel (Window > Reference). Read over these few tips and "gotchas" about the Property Inspectors and their settings, though:

If you're looking for some quick formatting of a data table, check out the Format Table command in Dreamweaver's Commands menu. It hasn't been updated in awhile and it uses some cumbersome coding, but it contains dozens of quick-and-easy formatting templates for data display in a table. While you're at it, check out the Sort Table command, also in the Commands menu. Very handy!

Changing Table Size and Structure

How big do you want your table to be? How many rows and columns should it have? What about merging cells across columns or rows? All of these common tasks can be performed using the Table Property Inspector, the Document window, and the Modify > Table menu.

Setting (and Removing) Dimensions

You can set table and cell dimensions by typing numbers in the Property Inspector or by clicking and dragging table and cell edges in the Document window. Although the click-and-drag method is certainly more immediately gratifying and intuitive, it's very dangerous because it's so easy to lose track of which dimensions Dreamweaver is adding where. It's also frustrating because tables don't always resize the way you think they will when you're happily dragging edges around.

Adding and Removing Rows and Columns

When you inserted the table, you specified how many rows and columns it should have. But plans change. Nothing is set in stone.

Merging and Splitting Cells

You can also change a table's structure by merging and splitting cells. To merge two or more cells, select them and either choose Modify > Table > Merge Cells or click the Merge Cells button in the Property Inspector (see Figure 8.12). To split a cell into two or more cells, place the insertion point inside the cell and either choose Modify > Table > Split Cells or click the Split Cells button in the Property Inspector. A dialog box appears, asking how you want the cell split (see Figure 8.14). Choose your options and click OK to close the dialog box and split the cell.

Figure 8.14. The Split Cell dialog box.

What happens when you merge cells? Dreamweaver applies the rowspan or colspan attribute to one of the selected cells, and removes the other cells. Content from all selected cells is moved into the remaining cell. If it makes more sense to simplify the table's structure another way, howeverfor instance, if you've just merged cells across every row in a two-column table, creating, in essence, a one-column tableDreamweaver rewrites the table structure that way. It's possible to create some very sophisticated table structures with merged cells; if you let Dreamweaver take care of rowspan and colspan , nothing will go wrong with the code.

What happens when you split cells? When you split a cell into columns, Dreamweaver increases the number of columns in the table and adds a colspan attribute to all other cells in the current column. That's a pretty major structural change. The same thing happens when you split a cell into rows: The total number of rows in the table is increased, and row-span is added to other cells as needed.

Although there's nothing inherently wrong with merging or splitting cells, don't use these commands as a crutch to shore up badly structured tables. It's much better planning to figure out ahead of time how many rows and columns a table needs, and where cells need to be merged, than to start without planning ahead and merge and split until you've lost track of how the table is built.

[ LiB ]

Категории