tag, and cells with the tag—but there’s no column tag. Dreamweaver calculates the columns based on the number of cells in a row. If there are seven rows in a table, each with four cells, the table has four columns. In other words, the number of cells you add to a row determines the number of columns in the table.
Two tags introduced in HTML 4—the and tags—let you control various attributes of columns in a table. Unfortunately, Dreamweaver provides no easy way to add the tags. You can find out more about them, however, by checking out Dreamweaver’s built-in HTML reference (see page 472) or visit http://tinyurl.com/3whpctc for indepth information.
Frequently Asked Question
Suddenly Jumbo Cells When I added some text to a cell, it suddenly got much wider than the other cells in the row. What gives? It isn’t Dreamweaver’s fault, it’s how HTML works. Web browsers (and Dreamweaver) display cells to match the content inside. For example, say you add a three-column table to a page. In the first cell of the first row, you type in two words, you leave the second cell empty, and add a 125-pixel wide image in the third cell of that row.
Since the image is the biggest item, its cell is wider than the other two. The middle cell, with nothing in it, is given the least amount of space. Usually, you don’t want a web browser making these kinds of decisions. By specifying a width for a cell (page 286), you can force a browser to display a cell with the dimension you want. But keep in mind that there are exceptions to this rule; see “The contents take priority” on the next page.
Setting Cell Dimensions Specifying the width or height of a particular cell is simple: Select one or more cells and then type a value in the Property inspector’s W (width) or H (height) field. You can specify the value in either pixels or percentage. For instance, if you want a 50-pixel-wide cell, type in 50. For a cell you want to take up 50 percent of the total table width, type in 50%. Read the next section for details on the tricky business of controlling cell and table dimensions. You can also resize a column or row of cells by dragging a cell border. As your cursor approaches the cell’s edge, it changes shape to indicate that you can begin dragging. Dreamweaver also provides an interactive display of cell widths (circled in Figure 7-7) when you use this method. This helpful feature lets you know the exact width of your cells at all times, so you can drag a cell to a precise width.
286
dreamweaver cs5.5: the missing manual
Modifying Cell and Row Properties
Figure 7-7: As you drag the border between cells, Dreamweaver shows you the changing widths of the two adjacent cells in real time. The width values change to blue and update themselves as you move your mouse.
Tips for Surviving Table-Making Nothing is more confounding than trying to get your tables laid out exactly as you want them. Many beginning web designers throw their hands up in despair when working with tables, which often seem to have minds of their own. Here are a few problems that often confuse designers—and some ways that make working with them more straightforward. The contents take priority Say you create a 300-pixel-wide table and set each cell in the first row to 100 pixels wide. You insert a larger graphic into the first cell, and suddenly—kablooie! Even though you set each cell to 100 pixels wide, as shown in Figure 7-8, the column with the graphic is much wider than the other two. Figure 7-8: Because a web browser can’t shrink the image or hide part of it, the cell has to grow to fit it. That first column of cells is now 120 pixels wide; the other two columns must shrink in order to keep the table 300 pixels wide. The numbers at the bottom of each cell indicate its width as set in the HTML—100—and the actual width as displayed in Dreamweaver in parentheses (120, 79, and 79).
chapter 7: tables
287
Modifying Cell and Row Properties
That’s because an individual cell can’t be smaller than the largest piece of content inside it. In this case, although you told the cell to be 100 pixels wide, the image is 120 pixels wide, which forces the first column to grow (and the others to shrink) accordingly. There’s no such thing as column width—only cell width To set the width of a column of cells, you have to set the width of only one cell in that column. Say you have a table with three rows and three columns. You need to set only the width for the top row of cells; you can (and should) leave the cell widths for the remaining cells in the two bottom rows empty. In fact, that’s what Dreamweaver does automatically—when you drag a vertical border between cells, Dreamweaver only modifies the Width property of the top cells. This principle can save a lot of time and, because it reduces the amount of code on a web page, it makes your pages load (and therefore appear) faster. The same holds true for the height of a row. You need only to set the height of a single cell to define the height for its entire row. When you drag a horizontal border, Dreamweaver adds a height property to the first cell in the row above the border. Tip: You can actually set the width of a column if you use the and tags when creating a table. Unfortunately, Dreamweaver doesn’t provide any way, aside from hand coding, to add those tags. But if you’re interested, you can learn more about how to use those tags and CSS to define the width of individual table columns at http://tinyurl.com/5qt25f.
Do the math Calculators are really useful when you build tables. Although you could create a 400-pixel-wide table with three 700-pixel-wide columns, the results you’d get on the screen could be unpredictable (after all, 700 plus 700 plus 700 does not equal 400). As it turns out, web browsers’ loyalty is to table width first, and then column width. If the combined widths of your columns add up to the width of your table, you’ll save yourself a lot of headaches. Don’t forget that you need to account for borders, cell padding, and cell spacing. For example, say you create a 500-pixel-wide table with two columns and 10 pixels of padding. If you want the first column 100 pixels wide, you’d set the width value to 80 pixels: 10 pixels of left padding plus 80 pixels of cell space plus 10 pixels of right padding equals 100 pixels total width.
288
dreamweaver cs5.5: the missing manual
Adding and Removing Cells Frequently asked question
Beware the Resize Handles Dreamweaver provides several techniques for resizing tables and cells in Design view. Unfortunately, the easiest way to resize a table—dragging a cell or table border—is also the easiest way to make a mistake. Because moving the cursor over any border turns it into the Resize tool, almost every Dreamweaver practitioner drags a border accidentally at least once, overwriting carefully calculated table and cell widths and heights.
table selected, you’ll set the table’s height property. As mentioned in the note on page 283, it’s actually invalid HTML to add a height attribute to the table tag. On occasions like these, don’t forget Dreamweaver’s undo feature, Ctrl+Z (-Z). And if all is lost, you can always clear the widths and heights of every cell in a table (using the Property inspector’s buttons) and start over by typing in new cell dimensions (see Figure 7-5).
In addition, if you grab either of the two bottom resize handles (they look like black squares) when you have a
Adding and Removing Cells Even after you insert a table into a web page, you can add and subtract rows and columns. The text or images in the columns move right or down to accommodate their new next-door neighbors.
Adding One Row or Column To add a single row to a table, use any of these approaches: • Click inside a cell. On the Insert panel’s Layout category, click the Insert Row Above button (see Figure 7-9) to add a row above the current row. Click the Insert Row Below button to add a row below the current row. • Click inside a cell. Choose Modify➝Table➝Insert Row, or press Ctrl+M (-M) to insert a new row of cells above the current row. Alternatively, you can right-click (Control-click) a cell, and then, from the shortcut menu, choose Table➝Insert Row. • To add a new row at the end of a table, click inside the last cell in the table, and then press Tab. The new rows inherit all the properties (except width) of the row you originally clicked.
chapter 7: tables
289
Adding and Removing Cells
Figure 7-9: Four buttons in the Layout category of the Insert panel make it easy to add columns and rows. They also make it easy to control where a new row or column goes—a feat not possible with a simple keyboard shortcut. On a side note, you’ll find the IFrame button on the Insert panel less than helpful—it merely jumps to Code view and inserts the HTML <iframe> tag. You don’t get a WYSIWYG display when you add iframes. (Iframes let you embed an HTML page within another page. You can read up on this technology at http://tinyurl.com/ds6aj.)
To add a single column of cells: • Click inside a cell. On the Insert bar’s Layout tab, click the “Insert Column to the Left” button to add a column to the left of the selected one. Click the “Insert Column to the Right” button to add a column to the right of the current column. • Click inside a cell, and then choose Modify➝Table➝Insert Column. • Click inside a cell, and then press Ctrl+Shift+A (-Shift-A). • Right-click (Control-click) a cell, and then, from the shortcut menu that appears, choose Table➝Insert Column. In each case, a new column appears to the left of the current one.
Adding Multiple Rows or Columns If you need to add a lot of rows or columns to a table, you use a special dialog box. 1. Click inside a cell. Choose Modify➝Table➝”Insert Rows or Columns.” The “Insert Rows or Columns” dialog box appears (see Figure 7-10).
290
dreamweaver cs5.5: the missing manual
Adding and Removing Cells
Figure 7-10: The “Insert Rows or Columns” dialog box lets you add multiple rows or columns to a table. The wording of the options changes depending on which you want to insert.
2. Click either Rows or Columns. Type the number of rows or columns you wish to add. Windows users can also click the tiny up- and down-arrow buttons next to “Number of rows” (or columns). 3. Tell Dreamweaver where you want the new rows or columns to appear, relative to the cell you selected, by clicking Above or Below (for rows), or Before or After (for columns). Click OK to insert them. Using the dialog box gives you an advantage over the single row/single column expansion described above. There, new rows always go above the current cell, and new columns always go to the left. The dialog box lets you choose whether the new row or column comes before or after the selected cell, as shown in Figure 7-10.
Deleting Rows and Columns To delete a row from your table, use one of the following techniques. Note: When you remove a row or column, Dreamweaver eliminates everything inside the cells. So before you start hacking away, it’s a good idea to save a copy of the page.
• Select the row (see page 279) and then press Delete to remove all the row’s cells—and everything in them. • Click a cell. Choose Modify➝Table➝Delete Row, or use the keyboard shortcut Ctrl+Shift+M (-Shift-M). • Right-click (Control-click) inside a cell, and then, from the shortcut menu, choose Table➝Delete Row. Deleting a column is equally straightforward. • Select the column (page 279), and then press Delete. You just eliminated all the selected cells and everything in them.
chapter 7: tables
291
Merging and Splitting Cells
• Click a cell, and then choose Modify➝Table➝Delete Column, or use the keyboard shortcut Ctrl+Shift+Hyphen (-Shift-Hyphen). • Right-click (Control-click) inside a cell, and then choose Table➝Delete Column from the shortcut menu. Warning: Dreamweaver doesn’t let you delete a row if you merged one of its cells with a cell in another row. Nor can you delete a column if it contains a cell merged with an adjacent cell. (You’ll learn about merged cells in the next section.)
Deleting a column like this is actually quite a feat. Since there’s no column tag in HTML, Dreamweaver, behind the scenes, has to select individual cells in multiple rows—a task you wouldn’t wish on your worst enemy if you had to do it by editing the raw HTML.
Merging and Splitting Cells Cells are very basic creatures with some severe limitations. For example, all the cells in a row share the same height. One cell can’t be taller than the cell next to it, which can pose some serious design problems. In the old days of table-based design, designers solved this problem by combining multiple cells to form, for example, one wide banner area that spans three table columns. Warning: If you’re still using tables for page layout, be careful when merging cells; as a technique for managing a page layout, merged cells can be big trouble. For more information, go to http://www.apptools.com/rants/spans.php. (P.S. You really don’t have to use tables for layout anymore. Turn to Chapter 9 and learn how to use CSS to architect your pages.)
But even when your tables contain just data, there are times when you need to combine multiple cells. The table in Figure 7-11, for example, breaks down data for a single year—like 2006—into two demographic groups—men and women. Since the data in the “men” and “women” columns pertain to particular years, you can merge two table cells to identify the first year, 2006, and combine two additional cells for the year 2007. Dreamweaver provides several ways to persuade cells to work well together. The trick is to merge cells—combine their area—to create a larger cell that spans two or more rows or columns. To merge cells, start by selecting the cells you want to merge, using any of the methods described in “Selecting Parts of a Table” on page 278. (You can only merge cells that form a rectangle or square. You can’t, for instance, select three cells in a column, and only one in the adjacent row, to create an L shape. Nor can you merge cells that aren’t adjacent; in other words, you can’t merge a cell in one corner of a table with a cell in the opposite corner.)
292
dreamweaver cs5.5: the missing manual
Merging and Splitting Cells
Figure 7-11: You can create cells that span multiple rows and columns by merging adjacent cells. This is one way to represent multiple related rows or columns of information using a single table header.
Then, on the Property inspector, click the Merge Cells button (Figure 7-12) or choose Modify➝Table➝Merge Cells. Dreamweaver joins the selected cells, forming a single new super cell. Figure 7-12: The Merge Cells button is active only when you select multiple cells. The Split Cells button appears only when you select a single cell, or you clicked inside a cell (see below for more on splitting cells).
Tip: Better yet, use this undocumented keyboard shortcut: the M key. Just select two or more cells, and then press M. It’s much easier than the keyboard shortcut listed in the online help: Ctrl+Alt+M (-Option-M).
You may also find yourself in the opposite situation: You have one cell that you want to divide into multiple cells. To split a cell, click or select, a single cell. In the Property inspector, click the Split Cells button. (Once again, you can trigger this command in several ways. You can choose Modify➝Table➝Split Cell. And if you prefer keyboard shortcuts, you can press Ctrl+Alt+S [-Option-S]. You can even right-click [Control-click] the selected cell, and then, from the shortcut menu, choose Table➝Split Cell.) When the Split Cell dialog box opens (Figure 7-13), click one of the buttons to indicate whether you want to split the cell into rows or columns. Then type the number of rows or columns you want to create, and click OK.
chapter 7: tables
293
Tabular Data
Figure 7-13: The Split Cell dialog box lets you divide a single cell into multiple cells. You can choose whether to divide the cell into rows (multiple cells on top of one another) or columns (multiple cells side by side).
If you split a cell into columns, everything in the cell winds up in the left column, with the new, empty column or columns to the left. When you split a cell into rows, the current contents end up in the top row.
Tabular Data Since tables are meant to display data, Dreamweaver provides useful tools for you to import and work with data.
Importing Data into a Table Say your boss emails you your company’s yearly sales information, which includes data on sales, profits, and expenses organized by quarter. She asks you to get this up on the Web for a board meeting she’s having in half an hour. This assignment could require a fair amount of work: building a table and then copying and pasting the correct information into each cell of the table, one at a time. Dreamweaver makes your task much easier, because you can create a table and import data into its rows and columns, all in one pass. For this to work, the table data you want to import must begin life in a delimited format—a task that most spreadsheet programs, including Excel, and database programs, such as Access or FileMaker Pro, can export delimited data easily. In most programs, you do this by choosing File➝Export or File➝Save As, and then choose a tab-delimited or comma-separated text file format. Note: Windows users don’t need to create a delimited-format file for Microsoft Excel. Dreamweaver for Windows directly imports Excel data and converts it into a well-organized table. See page 88 for details.
In a delimited file, each line of text represents one table row. The individual pieces of information in that line of text are kept discrete using a special character called a delimiter—most often a tab, but possibly a comma or colon. Each discrete piece of data will go into a single cell in the row. In a colon-delimited file, for example, Dreamweaver would convert the line Sales:$1,000,000:$2,000,000:$567,000:$12,500 into a row of five cells, with the first cell containing the word Sales. 294
dreamweaver cs5.5: the missing manual
Tabular Data
Once you save your boss’s spreadsheet as a delimited file, you’re ready to import it into a Dreamweaver table: 1. Choose File➝Import➝Tabular Data. The Import Tabular Data dialog box appears (Figure 7-14). Figure 7-14: The Import Tabular Data dialog box lets you select a text file of data to import and choose formatting options for the table.
2. Click Browse. In the Insert Tabular Data dialog box, find and select the delimited text file you want to import. The delimited file is no longer a spreadsheet, but a plain text file. Navigate to and double-click the file name in the dialog box. 3. From the pop-up menu, select the delimiter used to separate the data in the text file. You choose from Tab, Comma, Colon, Semicolon, or Other. If you select Other, an additional field appears, where you type in the character used as the delimiter. 4. Select a table width. Choose “Fit to data” if you want the table to fit itself to the information you’re importing—an excellent idea when you aren’t completely sure how much information the file contains. (You can always modify the table after you import the data.) On the other hand, if your web page needs a table of a certain size, you can specify it by selecting the Set button, and then typing a value in the field next to it. Select “pixel” or “percentage value” (see page 277). 5. Set values for “Cell padding,” “Cell spacing,” and “Border,” if you like. See page 276 for details.
chapter 7: tables
295
Tabular Data
6. Select a formatting option for the top row of data. If the first line in the text file has column headings—Quarter 1 Sales, Quarter 2 Sales, and so on—Dreamweaver lets you choose Bold, Italic, or Bold Italic to set this row apart from the rest of the table. Unfortunately, this option doesn’t turn the cells in the first row into table header () tags, which is what they should be. It’s best to choose no formatting, manually select the cells, and then turn them into table header ( | ) tags as described on page 285. 7. Click OK to import the data and create the table. Dreamweaver adds the table to your web page. It’s a regular HTML table at this point and you can edit the contents as you normally would, or modify the table (add rows and columns, for example) using any of the techniques discussed in this chapter.
Sorting Data in a Table If you have a table that lists employee names, you probably want to present that list in alphabetical order—or alphabetically and by department. Dreamweaver’s Sort Table command takes a lot of the drudgery out of this task. 1. Select the table you want to sort. See page 278 for some table-selection techniques. 2. Choose Commands➝Sort Table. The Sort Table dialog box appears (Figure 7-15). Figure 7-15: The Sort Table command works well with Dreamweaver’s Import Tabular Data feature. Imagine you get a text file listing all your company’s employees. You import the data into a table, but realize that the names aren’t in any particular order.
296
dreamweaver cs5.5: the missing manual
Tabular Data
3. Using the “Sort by” pop-up menu, choose the column by which you want to sort. You can choose any column in the table. Suppose you have a table listing a bunch of products. Each row has the product name, number, and price. To see the products listed from least to most expensive, sort by the column with the product prices. Tip: The Spry Data Set tools let you create a table that your website guests can sort interactively. You can read about this cool tool on page 607.
4. Use the next two pop-up menus to specify how you want Dreamweaver to sort the data. You can sort it alphabetically or numerically. To order the product list in the example above by price, choose Numerically from the Order pop-up menu. If you’re sorting a Name column, choose Alphabetically. Use the second pop-up menu to specify whether you want an Ascending (A–Z, 1–100) or Descending (Z–A, 100–1) sort. 5. If you like, choose an additional column to sort by, using the “Then by” popup menu. This secondary sort can come in handy when several cells in the first sorting column have the same value. If several items in your product list cost $100, a sort by price would place them consecutively in the table; you could then specify a secondary sort that would place the products in alphabetical order within each price group. Doing so lists all the products from least to most expensive, and lists all same-priced products alphabetically within their group. 6. If the first row of the table contains data you want to sort, turn on “Sort includes the first row.” If, however, the first row contains headings for each column, leave this box turned off. 7. Choose whether you want to sort header rows and footer rows as well. The Sort Header Row option isn’t referring to cells that have the “header” property set (see page 285). This option, and the next one, refer to the (table header) and | |