HTML COLSPAN and ROWSPAN table settings

Table cells can span across more than one column or row. The attributes COLSPAN (“how many across”) and ROWSPAN (“how many down”) indicate how many columns or rows a cell should take up.

For example, we might want to create header cells for each department in our table of names and phone numbers. In this table, the header cells in the first and fifth rows span across two columns to indicate the department for each group of names.










Production
Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales
Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

which gives us:

Production
Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales
Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

It often happens with multiple-column cells that a little color helps to set off the headers, giving the table a more visually organized look. Let’s add some color to the headers using BGCOLOR.










Production
Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales
Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

which gives this table:

Production
Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales
Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

ROWSPAN sets how many rows a cell spans. ROWSPAN can get a little confusing because it requires you to think through how the cell affects the rows after the row it starts in. It’s particularly useful in this situation to add borders to the table during the design process, even if the table won’t ultimately use borders.

This table code creates two header cells which span three rows each:






















Production Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

which creates

Production Raha Mutisya 1493
Shalom Buraka 3829
Brandy Davis 0283
Sales Claire Horne 4827
Bruce Eckel 7246
Danny Zeman 5689

Note that in the two rows after each header, the first cell in the row ends up in the second column because the first column is taken up by the multi-column cell.

Advertisements

2 thoughts on “HTML COLSPAN and ROWSPAN table settings

  1. Pingback: The Best Salsa Shoes 3/12/2010 | SALSA SHOES

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s