The Wayback Machine - https://web.archive.org/web/20081201053000/http://www.webreference.com:80/html/tutorial11/3.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

Trials and Tabulations

Splitting Up Tables


Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Table Columns

Tables are specified in rows, as we saw earlier. HTML 4.0 introduced a method of grouping the table in terms of columns as well. This is done through the use of the COL and COLGROUP elements. The use of these elements is slightly tricky. Although these elements identify columns, that obviously contain cells, they are not the parents of table cell elements. Let me explain that again: a COL element, that identifies a column in a table, will not have the cells in that column as its children. The cells will be children of the TR element that identifies the row they belong to. The COL and COLGROUP elements are used to specify information about the columns, and the user agent will take care of determining which cells belong to which columns. This is all best illustrated by an example:

<H4>Soft Drinks Consumed by Acme Programmers</H4>

<TABLE>
<COLGROUP>
 <COL SPAN=3 ID="date">
</COLGROUP>
<COLGROUP SPAN=5>
</COLGROUP>
<COLGROUP>
 <COL ID="total">
 <COL ID="change">
</COLGROUP>
<TR>
 <TD>Day</TD><TD>Month</TD><TD>Year</TD>
 <TD>Arnold</TD><TD>Bob</TD><TD>Carla</TD>
 <TD>Daphne</TD><TD>Eric</TD>
 <TD>Total</TD><TD>Change</TD>
</TR>
<TR>
 <TD>16</TD><TD>January</TD><TD>1999</TD>
 <TD>34</TD><TD>56</TD><TD>12</TD><TD>144</TD>
 <TD>5</TD>
 <TD>251</TD><TD>+27</TD>
</TR>
<TR>
 <TD>17</TD><TD>January</TD><TD>1999</TD>
 <TD>26</TD><TD>48</TD><TD>8</TD><TD>98</TD><TD>2</TD>
 <TD>182</TD><TD>-69</TD>
</TR>
</TABLE>

This time I didn't even try showing you this example in this page, because it will, even though it is perfectly legal HTML, crash various minor versions of Navigator 4.0 without any warning or recovery. Do I have to point out that Navigator doesn't support columns?

Again, such bugs are almost always caused by the combination of complicated tables and CSS. In a couple of years, you will probably be able to use them and tell people who use 4.0 browsers to get an earlier version if they complain, but right now they're a no-no for publicly available HTML documents unless you want a deluge of e-mail from readers saying that your document crashes their browser with no warning.

Explorer does columns pretty well. The primary point of having column elements is so that you can apply CSS declarations to all the cells in a column, which would not be possible with normal CSS selectors unless, say, you give all the cells in each column the same CLASS attribute.

Each table implicitly has one column group that covers all of its columns, even if you don't explicitly specify a COLGROUP element. Alternatively, you can specify several column groups, each spanning a number of columns, with a syntax like the following:

<COLGROUP SPAN=3 ID="cols1-3">
</COLGROUP>
<COLGROUP SPAN=2>
</COLGROUP>
<COLGROUP SPAN=5>
</COLGROUP>

The above specifies three column groups, the first one spanning 3 columns, the second one spanning 2 columns, and the third one spanning 5 columns. If you want to single out the two columns in the second group, you can omit the SPAN attribute and instead insert COL elements inside the COLGROUP. Note that COL elements are empty elements, and hence do not require an end-tag.

<COLGROUP SPAN=3 ID="cols1-3">
</COLGROUP>
<COLGROUP>
 <COL ID="col4">
 <COL ID="col5">
</COLGROUP>
<COLGROUP SPAN=5>
</COLGROUP>

The SPAN attribute also applies to COL elements, meaning that you can specify several columns in one element, like this:

<COLGROUP SPAN=3 ID="cols1-3">
</COLGROUP>
<COLGROUP>
 <COL ID="col4">
 <COL ID="col5">
</COLGROUP>
<COLGROUP>
 <COL SPAN=4 ID="cols6-9">
 <COL ID="col10">
</COLGROUP>

This is rather complicated syntax and can be potentially confusing, so let me explain this in detail: The first COLGROUP element covers the first three columns. The second COLGROUP element contains two COL elements, and covers the fourth and fifth columns. The elements themselves each specify one column. The third COLGROUP element contains one COL element with a SPAN of 5 and another with no SPAN attribute (which is the same as SPAN=1). The first COL element specifies four column, but the element represents each of these columns not all of them together. This is best illustrated by example. Consider the following style sheet applying to the above example:

COLGROUP#cols1-3 { width: 30%; }
COL#cols6-9 { width: 5%; }

The first declaration means that the column group containing columns 1, 2 and 3 will have a width equal to 30% of their parent, so if you add the widths of columns 1, 2 and 3 the result should be 30% of their parents width. The columns themselves could have any width as long as that is true. The second declaration means that each of the columns 6, 7, 8 and 9 will have a width equal to 5% of their parent. If you add their widths together, you should get 20% of their parent's width.

Front Page123456789

Produced by Stephanos Piperoglou

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
The Geek Wishlist - Ten Tech Toys for the Holidays · Cool Tool for Asterisk Developers · Wi-Fi We Can Be Thankful For

URL: http://www.webreference.com/html/tutorial11/3.html
Created: Feb 10, 1998
Revised: Feb 16, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.