Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Adobe Dreamweaver

This chapter is from the book

Using Flexible Widths Sensibly

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.

Figure 8.16Figure 8.16 A flexible-width table using a control row for stabilization.

TIP

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.

Making Your Tables Accessible

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!

Accessibility for Data Tables

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.

and

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:

State

Capital City

New Mexico

Santa Fe


<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:

 

Store 1

Store 2

Chocolate Bars

355

20

Popsicles

25

500


<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> 
Caption and Summary

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.

Accessibility for Layout Tables

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 tables—table headers, captions, summaries, and so on—for layout tables. Structurally (as well as graphically), layout tables should be invisible.

Making Tables Accessible in Dreamweaver

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.

Header Cells and the scope Attribute

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.

Figure 8.17Figure 8.17 Creating header cells with the Table object.

Captions and Summaries

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 it—or 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:

  1. In Design view, select the table. (This is just to help you find the code for the table after you switch views.)

  2. Switch to Code view or Code and Design view, and find the opening table tag. Put the insertion point immediately after the tag.

  3. In the HTML Insert bar, from the Table object group, choose the Table Caption object (see Figure 8.18). This inserts an empty caption tag in the code.

  4. Between the opening and closing caption tags, enter the text you want for your caption.

Figure 8.18Figure 8.18 Inserting a caption with the Table Caption object.

NOTE

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).

CSS and Your Tables

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.

Applying CSS to Tables

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).

Figure 8.19Figure 8.19 Using the Tag Selector to apply a custom class to a table.

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.

CSS Properties and Table Formatting

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.

Border Effects

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.

Figure 8.20Figure 8.20 Applying a border to a table style.

Background Colors and Images

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.

Figure 8.21Figure 8.21 Applying a background image and color to a table style.

Width and Cell Padding

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.

Aligning Cell Contents

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).

Exercise 8.1 Creating a CSS-Styled Data Table

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 http://www.peachpit.com to your hard drive. Define a site called Chapter 8, using the chapter_8 folder as the local root folder.

  1. Create a new file. Save it in your site folder as holidays.html. Figure 8.22 shows what you're going to create in this file.

  2. Figure 8.22Figure 8.22 The holidays.html table as it will look when completed.

  3. Working in either Standard or Expanded Tables modes, insert a table with the following settings:

  4. rows: 2

    columns: 4

    width: 500

    cellpadding: 10

    cellspacing: 0

    border: 0

    For headings, choose to create a row of header cells across the top of the table (a look at Figure 8.22 will tell you why). For the caption, enter Holiday Checklist. Leave the summary blank. Clock OK to close the dialog box and insert the table.

  5. Enter the following headings into the header cells across the top of the table: Holiday, Date, Images, Activities. In the next row, enter your favorite holiday and its information. Keep adding rows and holiday entries until you have four or five entries. (Remember, you can press Tab while in the last cell of the table to quickly add a new row.)

  6. Now that you have data in the table, select it and remove the width. The data will hold it open.

  7. Open the CSS Styles panel and click the New Style button to create a new style. Create a new custom class called .holiday for this document only (see Figure 8.23). Click OK to open the CSS Styles Definition dialog box.

  8. Figure 8.23Figure 8.23 Creating the holidays custom class.

  9. This custom class will be applied to the entire table. It's going to hold only two items: text-formatting options and a width indicator. In the Type category of the CSS Style Definition dialog box, set whatever type formatting you like—font, size, color, and so on. When the style is applied, this will govern all type within your table. Go to the Box category and set the Text Align option to Left. This will left-align all text within the table.

  10. To set the table width, go to the Box category. In the width field, type 100%.

    Click OK to close the dialog box and create the custom class.

  11. In the Document window, place the insertion point inside the table you created. In the Tag Selector, find the table tag and right-click on it. From the contextual menu, choose Set Class > Holiday (see Figure 8.24). You just used the Tag Selector to help you select a table and apply a CSS class. Very nice! The text in your table changes its formatting, and the table width stretches across the page.

  12. Figure 8.24Figure 8.24 Using the Tag Selector to select a table and apply a CSS class to it.

  13. You want to apply a certain set of style formatting to all header cells in the table, but not necessarily to all header cells in all tables throughout the document. So, you'll define a contextual selector that applies only to header cells that occur within elements governed by the holiday class.

  14. In the CSS Styles panel, click the New Style button. Create a new CSS Selector with the name .holiday th (see Figure 8.25). In the CSS Style Definition dialog box, go to the Background category and assign a background color. Click the Apply button to see the new style take effect. Adjust the background color, if you like. Then click OK to close the dialog box and create the style.

    Figure 8.25Figure 8.25 Creating a contextual selector to format all headers within a holidays-styled element.

  15. Now you'll do the same thing to format all data cells within the holiday table. In the CSS Styles panel, click the New Style button. Create a new CSS Selector with the name .holiday td. In the CSS Style Definition dialog box, go to the Border category. Set a solid, black, 1-pixel border across the top only (see Figure 8.26). Click OK to close the dialog box and create the style.

  16. Figure 8.26Figure 8.26 Creating a top border for each table cell in the holidays table.

  17. To control the appearance of the caption, you'll redefine the caption tag. (This will affect all captions, regardless of whether they're part of a holiday table.) In the CSS Styles panel, click the New Style button and redefine caption. In the CSS Style Definition dialog box, to increase the space between the caption and the table, go to the Box category and set a bottom padding of 10 (see Figure 8.27). When you're done, click OK to close the dialog box.

  18. Figure 8.27Figure 8.27 Using padding to separate a table caption from its table.

  19. Finally, experiment with a table background. In the CSS Styles panel, select the holiday style and click the Edit Style button. When the dialog box opens, go to the Background category and click the Browse button to choose a background image. From the category_08 folder, choose the brown_ribbon.gif file. Move the dialog box so you can see the table, and click the Apply button. Experiment with different settings to see how they look. To re-create the example shown in Figure 8.22, set the Repeat to No-Repeat and the Vertical and Horizontal positions to Center and Bottom, respectively. When you're done, click OK to close the dialog box.

  20. Take your CSS-styled table for a test drive in as many different browsers as you can. How does it fare?

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020