spacer

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

Trials and Tabulations

Splitting Up Tables


Developer News
Get Ready for Microsoft's 'Oslo' Modeling Tool
Latest Linux Hits Networking Flaws
Metasploit 3.2 Offers More 'Evil Deeds'

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


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel Article: Using Power & Display Context in the Intel Mobile Platform SDK
Internet.com eBook: Real Life Rails
IBM SCA Center Article: Simplifying Composite Applications with Service Component Architecture
Intel PDF: Quad-Core Impacts More Than the Data Center
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Intel PDF: Analysis of Early Testing of Intel vPro in Large IT Departments
Internet.com eBook: Best Practices for Developing a Web Site
Intel PDF: IT Agility through Automated, Policy-based Virtual Infrastructure
IBM CIO Whitepaper: The New Information Agenda. Do You Have One?
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
IBM Whitepaper: How are other CIOs driving growth?
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Actuate Download: Free Visual Report Development Tool
Red Gate Download: SQL Backup Pro
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
IBM SCA Download: Start Building SCA Applications Today
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Anatomy of an Ajax Application · Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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