Forum Moderators: open

Message Too Old, No Replies

Default Table and Column Widths

Questions about the default Table and Column Widths when no width is set.

         

snair

8:04 am on May 30, 2006 (gmt 0)

10+ Year Member



I have a question in regards to table and column widths.

According to the W3C, if I have a table with no given width, then the width is determined by the user agent.

And along the same vein, if I have a column with no width, the column will only be as wide as the widest element within it.

On most of the browsers that I tested (mainly FF and IE5+ on Windows), this means that the table width will adjust to the sum of the columns.

What I’m wondering is this:

1. Are there cases (e.g. certain browsers) where the table width is GREATER than the sum of the no-width columns?

2. Are there cases where a no-width column will have a greater width than the widest element within it?

3. And lastly, is it strongly recommended to have both a table width and a column width? I know it’s suppose to help speed of the rendering of tables, but is it ok to not have it?

Thanks for any clarification on this!

BlobFisk

11:09 am on May 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can still set column widths using CSS. The width attribute on <td> elements has been deprecated as it was decided that allowing the user agent to determine widths was the best thing (as you said, one of the reasons was render speed).

Using CSS you can control these. As to you questions:

  1. Not unless a width has been specified on the table itself.
  2. Again, not unless a width has been specified on the table itself.
  3. The recommendation is to allow the user agent to do its own thing, however, in my opinion using CSS to control (or more accurately, influence!) widths for you design is ok.

HTH

snair

1:50 pm on May 30, 2006 (gmt 0)

10+ Year Member



Thank you very much BlobFisk!

TechnoGeek

10:38 am on Jun 3, 2006 (gmt 0)

10+ Year Member



Hello, snair.
As of HTML 4, the WIDTH, HEIGHT, NOWRAP, and BGCOLOR attributes are
all deprecated in favor of style sheets. However, if you like to use
them (as I do) you should use

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

at the top of the document.

rocknbil

4:16 pm on Jun 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

If you don't include the URL, it's nearly the same as having no doctype at all.

snair

4:57 pm on Jun 5, 2006 (gmt 0)

10+ Year Member



Thanks TechnoGeek and Rocknbil!

The main reason I asked this is because I'm generating this table of data based on filters that the user selects--so the table can have any number of columns.

And so I want the column widths to be semi-based on the data within them (i.e. the width should be no longer than the data, but at the same time, wrap if the browser window is smaller).