|[ LiB ]|
Believe it or not, flexible tables are often harder to create than fixed-width tables. This is because although you want the overall table to have a flexible width, you probably don't want all columns to resize. Generally , flexible tables are built with one flexible column and one or more fixed-width columns. Getting this column to flex while that one doesn't takes a few extra steps.
Flexible tables that mix fixed and flexible columns almost always do better with a control row to help them. For each fixed-width column in the control row, insert a spacer graphic as described in the previous section, sized to the desired column width. For the flexible-width column, insert a spacer graphic sized to whatever minimum width you want for this column; then assign the cell itself a width of 100%. That means the cell should take up 100% of the space available to it, which is the entire width of the table, minus the fixed widths being propped open by the spacer graphics in your other columns. Figure 8.16 shows the control row set up for a flexible table.
If you want to make sure the right columns are flexing in your flexible-width table, try temporarily assigning each cell a different background color . When you preview in the browser, you'll see clearly what's flexing and what isn't.
According to some accessibility pundits, tables are inaccessible tools of the devil and should never be used. But really, there's nothing wrong with using tables for displaying data or organizing page layout, as long as you follow the rules for making them accessible. It's not even that hard!
Section 508 has very little to say about tables, and what it does say applies only to data tables. Section 508, § 1194.22(g) and 1194.22(h), state:
Row and column headers shall be identified for data tables.
Markup shall be used to associate data cells and header cells for data tables that have two or more logical levels of row or column headers.
The first of these rules is applicable to any simply structured data table and can be accomplished using the th (table header) tag with the id attribute and the td (table data) tag with the headers attribute:
<table> <tr> < th id="State" >State</th> < th id="Capital City" >Capital City</th> </tr> <tr> < td headers="State" >New Mexico</td> < td headers="Capital City" >Santa Fe</td> </tr> </table>
The second rule applies to more complex data tables, where more than one axis of information is presented. It can be taken care of by using the scope attribute to specify whether the header cell controls a row or column:
<table> <tr> <th> </th> <th id="Store #1" scope="row" >Store #1</th> <th id="Store #2" scope="row" >Store #2></th> </tr> <tr> <th id="Chocolate Bars" scope="col" >Chocolate Bars</th> <td headers="Store #1 Chocolate Bars">355</td> <td headers="Store #2 Chocolate Bars">20</td> </tr> <tr> <th id="Popsicles" scope="col" >Popsicles</th> <td headers="Store #1 Popsicles">25</td> <td headers="Store #2 Popsicles">500</td> </tr> </table>
Section 508 says nothing about using captions or summaries for tables, although the W3C's Web Accessibility Initiative (WAI) suggests a priority 3 guideline to provide summaries for tables. However, many accessibility experts suggest using these to enhance your table's accessibility. A table's caption is a short sentence summarizing the contents of the table, which will appear in all browsers and can be visually styled using CSS. It looks like this in the code:
<table> <caption>States and their capital cities</caption> [etc] </table>
A summary is similar in functionality, but will not appear in a graphical browser. It looks like this in the code:
<table summary="States and their capital cities"> [etc] </table>
Because a caption and summary perform the same task, you don't need both.
Section 508 says nothing about layout tables. Although the W3C generally frowns on using tables for layout purposes (believing you should be using CSS instead), it offers the following guidelines for ensuring that they're accessible:
Do not use tables for layout unless the table makes sense when linearized. Otherwise, if the table does not make sense, provide an alternative equivalent (which may be a linearized version). [priority 1]
If a table is used for layout, do not use any structural markup for the purpose of visual formatting. [priority 2]
Keeping in mind that screen readers read tables in a linear fashion, from left to right and top to bottom, make sure that whatever content is in your layout table makes sense when read that way. If it doesn't, either restructure the table or provide a link to another page that contains the same material presented in a linear fashion (that is, without a table). Furthermore, don't use any of the markup usually associated with data tablestable headers, captions, summaries, and so onfor layout tables. Structurally (as well as graphically), layout tables should be invisible.
The Dreamweaver Table object makes it easy to create accessible data and layout tables. Just think carefully about how you fill out the options in the Insert Table dialog box, and the job is pretty much done. After you've created a table, it's harder to add, edit, or remove the accessibility attributes because most of them don't appear in the Property Inspector.
When you insert a table that will be used to present tabular data, be sure to choose one of the Headers options in the Insert Table dialog box to place your header cells in the first row, first column, or both. The table will be created with th tags for these cells, with the scope attribute already applied to each (see Figure 8.17). Pretty nice!
If you're creating a layout table, be sure to choose the None option for Headers, and no th tags will be added to the table.
After you've created the table, if you change your mind about what should and shouldn't be a header, select each cell in question and use the Header option in the Property Inspector to turn cells into headers or data cells. If you do this, however, be sure to keep track of the scope attribute! If you change existing header cells into data cells (by deselecting the Header option), the scope attribute remains in place, which it shouldn't because data cells don't have a scope. Because scope doesn't appear in the Property Inspector, you need to edit the code directly or use the Selection Inspector or the Tag Editor dialog box (Edit > Tag) to remove it. If you turn data cells into header cells (by selecting the Header option), no scope attribute is added. According to Section 508, you don't need the scope unless you have more than one level of header; but if you do have a complex table that requires scoping, you'll have to add the correct scope attribute by editing the code or using the Selection Inspector. Dreamweaver also won't stop you from doing something illegal, such as having too many header cells or having headers in illogical positions .
To add a caption or summary to a table while you're inserting it, just fill in the appropriate fields in the Insert Table dialog box. The caption displays in Design view (as well as in the browser window), so it's easy to see, select, and edit its text after it's in place. To edit the caption properties (such as alignment), use the Selection Inspector. The summary won't display, so you'll need to use the Selection Inspector or Tag Editor to work with itor even to remind yourself that it's there.
What if your table already exists and you want to add one of these items? The summary is coded as an attribute to the table tag, so you can select the table and use the Selection Inspector to add it.
It's a trickier proposition to add a caption to an already existing table. Because the caption is coded in its own tag and not as a table tag attribute, you can't use the Edit Tag command or Selection Inspector to create it. But you can do it in Code view:
For more in-depth information on table accessibility, see one of the books written specifically on web accessibility, such as Joe Clark's excellent Building Accessible Websites (New Riders, 2001).
Cascading Style Sheets make it possible to do some wonderful things to table display, all without cluttering up your table code with extra attributes. As always with CSS, be sure to preview in your target browsers to make sure your CSS formatting is supported. Some older browsers (such as Netscape 4) don't interpret all aspects of CSS table formatting properly.
You can apply CSS to tables by redefining the table , tr , th , or td tags in your style sheet; or, you can define custom classes or IDs and apply those to any of the table tags.
To apply a custom class or ID to a table, select the table and use the Class drop-down menu in the Table Property Inspector. Or, right-click on the table tag in the Tag Selector and choose Set Class or Set ID from the contextual menu (see Figure 8.19).
To apply a custom class or ID to a table cell, select the cell and use the Class drop-down menu in the top portion of the Property Inspector, or right-click the td , th , or tr tags in the Tag Selector and choose Set Class or Set ID from the menu.
Applying CSS to your tables can replace traditional HTML formatting for borders, backgrounds, widths, alignment, and even cell padding in tables. No matter which of the following properties you choose to style with CSS, remember to remove those properties from your table's HTML so you don't have any formatting conflicts.
To create a border as part of your table's style, create a new style and, in the CSS Style Definition dialog box, go to the Border category (see Figure 8.20). Here you can choose to assign a border to all four sides of a table element or only certain sides. You can specify solid, dashed, dotted , and other border styles (although not all are equally well supported in browsers, so be sure to check your results). Your border can be a pixel-based or other width. And it can be any color. You can also mix and match so that maybe the top border is black and fat, while the bottom border is gray and thin.
You can apply a border effect to any table element, but the tr tag doesn't always display borders properly, so you might want to apply it to tables and cells only.
Tables, rows, and cells can also have background colors and images applied to them using CSS styles. Create a new style and, in the CSS Style Definition dialog box, choose the Background category (see Figure 8.21). If you choose a background image, you can also control whether it tiles and how it positions itself within the element by using the Repeat, Horizontal Position, and Vertical Position options.
Table and cell width, and table cell padding can be controlled by CSS box properties. To access these properties in the CSS Style Definition dialog box, choose the Box category. Set the width field to any pixel, percent, or other type of value you desire . To adjust cell padding, set the Padding options. Warning, though: Not all browsers treat the CSS padding property well, so either preview carefully in your target browsers or don't use CSS to control cell padding. Cell spacing is also better coded without CSS.
You can center cell contents horizontally and vertically by using the CSS block properties. To access these properties in the CSS Style Definition dialog box, choose the Block category. Use the Text Align field (for horizontal alignment) and the Vertical Alignment field (for vertical alignment).
In this exercise, you'll build a data table and create CSS styles for table formatting. Along the way, you'll make sure it's accessible. Before you start, download the chapter_8 folder from the book's website at www.peachpit.com to your hard drive. Define a site called Chapter 8, using the chapter_8 folder as the local root folder.
|[ LiB ]|