- Inserting and Working with Tables
- Selecting Table Elements
- Modifying Table Properties Using the Property Inspector
- Modifying Cell Properties Using the Property Inspector
- Working with Tables in Expanded Tables Mode
- Importing Tabular Data
- Summary
Modifying Table Properties Using the Property Inspector
For precise formatting of tables, it's essential that you become familiar with the options revealed by the Table Property inspector. Shown in Figure 4.8, this Property inspector becomes available when the table is selected (for more on selecting tables, see the previous section).
Figure 4.8 Format table attributes from within the Table Property inspector.
As you can see from the callouts in Figure 4.8, the Table Property inspector allows you to set/customize the following attributes (moving from left to right):
- ID
- Rows and Columns
- Width
- Cell Padding and Cell Spacing
- Alignment
- Border
- CSS Class
- Clear Column Widths or Heights
- Convert Table Widths to Pixels
- Convert Table Widths to Percent
- Source
To demonstrate the use and functionality of these attributes and formatting options, let's rebuild the main page (index.html) of the Vecta Corp site.
If you open the index.html file for this chapter, it'll appear to be a blank document, but a couple of minor changes have been made. First, the title and background color have been preset for you. Second, the header_bg.gif image isn't included. As a matter of fact, this clunky (1 pixel by 2,000 pixels) image is no longer needed; it's being replaced altogether by a centered, cleaner design.
To begin this exercise, insert a new table into the Document window by selecting Insert, Table. When the Table dialog box opens, format the options in the table dialog box so that it contains one row, one column, has a width of 100%, contains no border, no cell padding, and no cell spacing. The configured Table dialog box will look like Figure 4.9.
Figure 4.9 Format the new table so that it contains one row, one column, has a width of 100%, contains no border, no cell padding, and no cell spacing.
Click OK to insert the new table into the Document window. With the table now in the Document window, you'll notice a few details. First and the most obvious is that the table spans the entire width of the Document window. Remember, this table is set to 100%. What that means is that no matter how I stretch the Files panel group on the right, the table will always automatically adjust to accommodate the width of the Document window—as it will do in the browser window as well. Second, you'll notice that the Table Widths Visual Aid displays the width of the table as a percentage, but just to the right of that figure displays the current width in pixels within parentheses. This value is simply for your information and is useful to reference in case you ever need to convert the table's percentage to a pixel value instead. Finally, you'll notice that even though we didn't specify a border, the table appears to contain a dotted border surrounding the perimeter of the table. This is actually a visual aid and not a border. This visual aid, which can be disabled by clicking the Visual Aids button on the Document toolbar and unchecking the Table Borders option, won't show in the browser.
With the table selected, you can now begin modifying various attributes within the Property inspector. Let's begin.
The Table ID
An attribute seldom used (unless you're working with JavaScript and/or CSS), the Table ID attribute allows you to uniquely identify the table so that it can be referenced from scripting languages. This attribute is entirely optional and will have no effect on the table if left empty. We'll use the Table ID as a simple way of identifying the tables throughout the chapter. If I say select the content table, you'll know what table to select. If I indicate select the header table, again, you'll know what table to select. With our existing table selected, enter the value header into the Table ID text box and press Enter (Return).
Adding and Removing Rows and Columns
As you might expect, there are numerous ways for adding and removing rows and columns after you've inserted a table. You could delete the table and reinsert it if you really wanted to, but there are simpler methods. For instance, to add a row, you could place your cursor within the last cell of the last row and press the Tab key. Doing this adds a new row. Alternatively, you could use the Insert Row option (press Ctrl+M/-M) available from the Table submenu within both the context menu, invoked by right-clicking (Control-clicking) the table, and the Modify menu. After the new row has been inserted, you can easily remove it by accessing the Delete Row option (press Ctrl+Shift+M/-Shift-M) from the Table submenu within either the context menu or the Modify menu. Another, more flexible, alternative for inserting rows is to use the Insert Rows or Columns dialog box available from the Table submenu in both the context menu and the Modify menu. Choosing this option opens the Insert Rows or Columns dialog box (see Figure 4.10).
Figure 4.10 Use the Insert Rows or Columns dialog box as an alternative method to inserting rows or columns within your table.
With the dialog box open, you'll immediately notice that you can not only insert a new row below the existing row, but can also insert a new row above the existing row. Even better, you have the option of inserting new columns before or after the column where your cursor is currently focused. Try entering the number 5 within the Number of Rows text box and click OK. As you can see from Figure 4.11, the rows are added to the table.
Figure 4.11 New rows are added to the table using the Insert Rows or Columns dialog box.
It's important to note that the previous methods work only when your cursor is focused within a cell. You can change the overall count of rows and columns for the table from the Property inspector by selecting the table and changing the text box values for Rows and Cols. To return my table back to its original state, I'll enter 1 within the Rows text box and press Enter (Return). The table will return to its original state.
Changing Table Sizes
Aside from adding and removing rows and columns, you also have the capability to change the width of the table directly from the Property inspector. You already saw how you can use the Table dialog box to initially set the width of the table (we set it to 100%); alternatively, you can set the width of the table directly within the Property inspector. Because I know that the image header.gif will reside within this table, and I know that the width of the image is 697 pixels, I'll change the width of the table now to this number by placing my cursor within the W text box, typing 697, making sure pixels is selected from the menu, and pressing Enter. As you can see from Figure 4.12, the width of the table is affected.
Figure 4.12 Change the width of the table to 697 pixels from within the Property inspector.
As your web pages become increasingly complex, you'll begin to realize that keeping track of your table's dimensions can get out of hand. If you ever feel like starting over, you can clear all widths and heights from both the table and cells within the table using the Clear All Widths and Clear All Heights options. You can access these options in one of three ways: First, you can choose these options from the Table Widths Visual Aid's list, as shown in Figure 4.13.
Figure 4.13 Select the Clear All Widths or Clear All Heights options to clear table or cell widths, respectively.
Second, you can clear column widths and column heights by clicking the Clear Column Widths and Clear Column Heights buttons located just below and to the right of the Table ID field on the Property inspector. Finally, you can perform the same operation by choosing the Clear Cell Heights and Clear Cell Widths options located in the Modify, Table submenu. Whichever method you choose results in the same action: either the height (for cells) or width is removed.
Modifying Cell Padding and Cell Spacing
Although it might not seem like it, the structure of our new Vecta Corp page is coming along nicely. As I'm sure you can tell, we're outlining the various properties outlined by the Table Property inspector while at the same time designing the header for our table-based page. And while there's still a lot to be done, let's move forward by adding the main header image to the cell within the header table. This can be done by locating the header.gif image within the Images folder of our defined site, selecting it, and dragging it over and into our table's cell. The result will appear similar to Figure 4.14.
Figure 4.14 Drag the header graphic into the table's cell to round out the heading for our web page.
Now that you have the header of the page squared away, it's time to build the bottom portion of the site. Yes, we could insert the contents of home.txt (located within the Assets folder) directly underneath the existing table; unfortunately, doing this would cause the text to align flush against the edge of the Document window as our margins are currently set to 0 pixels. Although we could fix this by adding a margin width, doing that would cause our table at the top of the page to shift to the right to compensate. Instead, we could create a table below our existing table and adjust its cell spacing or cell padding to make up for the necessary spacing. To do this, we'll begin by adding a new table. Begin the process by following these steps:
- Place your cursor just to the right of the header table.
- Choose Insert, Table. The Table dialog box appears.
- Give your new table 2 rows, 2 columns, a width of 697 pixels, a border thickness of 0, a cell padding of 0, and a cell spacing of 4.
- Click OK. Your new table will be inserted into the Document window, below the header table, and will look similar to Figure 4.15.
Figure 4.15 The new table is inserted and includes cell spacing to protect the content from the left edge of the page.
- Assign your table the ID content within the Table ID text box in the Property inspector (shown in Figure 4.15).
Now that the table is firmly in place, you can see that the cell spacing is available. Unlike the header table, which doesn't contain spacing around the edges of the table, our content table contains spacing around the table and between cells. This will become more obvious later, when you insert text into a cell.
Table Alignment
Now that we have both a header and a content table within our page, let's finish off the table structure by aligning both tables to the center of the page. To do this, select each table and then choose the option Center from the Align menu in the Property inspector so that each of your two tables is center-aligned on the page, similar to Figure 4.16.
Figure 4.16 Select each table and center align them on the page.
It's important to note that this option aligns only the table on the page, not the content within the table. To align the content within the table, you'll still need to select any content that you add within the table and choose the center align option from the Text Property inspector.
Working with Table Borders
There are a couple of methods for adding borders to your existing tables, but none more obvious than the Border text box option located within the Property inspector. Selecting a table and adding a value here (other than 0) creates a traditional, ordinary looking border. Nothing fancy here! We'll discuss a second option for adding borders in CSS in the next chapter.
Converting Table Widths to a Percentage or Pixels
Every now and then you might find the need to convert an existing table that was created using pixels into a percentage value or vice versa. For instance, our content table is displayed at the bottom of the page and has a fixed width of 697 pixels. Looking at the table and its width within the page, it appears to take up roughly 80% of the page. If I like this width, but prefer the width to be expressed in percentages as opposed to pixels, I can easily perform a conversion with a simple click of a button. To do this, I can select the table and choose Modify, Table, Convert Widths to Percent (shown in Figure 4.17).
Figure 4.17 Convert table widths to percentages.
Although you won't notice a significant difference initially, the Table Widths Visual Aid does, in fact, display the table width as a percentage followed by the pixel width within the parentheses. Just below that value is the width of the cell expressed as a percentage, again followed by the pixel width in parentheses.
Other options exist from the same menu, including Convert Widths to Percent, Convert Heights to Pixels, and Convert Heights to Percent. Furthermore, you can access these options directly from the Property inspector by choosing the icons located to the bottom-left of the Property inspector, just underneath the Table ID text box.