minimum width for table cols ignored

A

Aaron Fude

Hi,

I'm sure that this is a common problem so there's probably a source with all
the answers that I want.

I find that my width attribute in td and th tags is not honored - I end up
with narrower columns. This usually happens when the table has very many
colums and doesn't fit. I use css for layout so my table is inside an
absolutely positioned div - may be that's what's causing the problem?

In any case, has anyone had similar problems? If so, do you have any
suggestions? A good article to read?

Thank you,

Aaron
 
J

Jukka K. Korpela

Aaron Fude said:
I find that my width attribute in td and th tags is not honored - I
end up with narrower columns.

By definition, the width attribute for td and th elements specifies a
_suggested_ width, and in practice it normally acts as a _minimum_ width.
However, e.g. incompatible width attributes might conceivably result in
smaller widths being used.
This usually happens when the table has
very many colums and doesn't fit.
URL?

I use css for layout so my table is
inside an absolutely positioned div - may be that's what's causing
the problem?

Maybe. URL?

But what would you _like_ to happen? If a table does not fit, what should
a browser do? Using table-layout: fixed in CSS might produce more
predictable results, but it surely creates a large number of potential
problems.
 
M

Mitja

Aaron Fude said:
Hi,

I'm sure that this is a common problem so there's probably a source
with all the answers that I want.

I find that my width attribute in td and th tags is not honored - I
end up with narrower columns. This usually happens when the table has
very many colums and doesn't fit. I use css for layout so my table is
inside an absolutely positioned div - may be that's what's causing
the problem?

In any case, has anyone had similar problems? If so, do you have any
suggestions? A good article to read?

Sometimes the browsers do some "optimisations", e.g. shrinking the table so
 
B

Barry Pearson

Jukka K. Korpela wrote:
[snip]
But what would you _like_ to happen? If a table does not fit, what
should a browser do? Using table-layout: fixed in CSS might produce
more predictable results, but it surely creates a large number of
potential problems.

I believe it is not supported by IE-Mac, or earlier browsers?

(It typically, as you imply, isn't a good answer).
 
B

Barry Pearson

Aaron said:
Hi,
I'm sure that this is a common problem so there's probably a source
with all the answers that I want.

I find that my width attribute in td and th tags is not honored - I
end up with narrower columns. This usually happens when the table has
very many colums and doesn't fit. I use css for layout so my table is
inside an absolutely positioned div - may be that's what's causing
the problem?
[snip]

Tables are inherently difficult to control. They were intended to be that way,
and to adapt to the user's viewing conditions. I believe the best thing to do
with tables is to accept that they work best when their size is hardly
controlled at all. They are for positioning material in rows & columns, not
for pixel-level sizing.

If you want to control the sizes of table cells, control the content, not the
table. Then the table will simply adapt to the content. For example:

HTML:
<td>
<div class="width1">
content of the cell goes here
</div>
</td>

CSS:
div.width1 {
width: 200px;
overflow: auto:
}

If you want a minimum width, you could use a spacer-div. Put a zero-content
div in the cell, and control its width via CSS. (It is the modern equivalent
of a spacer-GIF).
 
A

Aaron Fude

Thank you for all the answers. Basically, problems arise in one situation.
When I
1. ...have way too much data to fit accross the screen (It just is and
supposed to be and my clients don't mind srolling. It's just a darn long
table!).
2. ...have two such tables and I want the columns to align.

Once you accept that the 'width' is a suggestion, I don't really see how to
achieve this. I guess spacer-div is the answer. Barry, can you point out an
example?

Unfortunately, I couldn't post a URL highlighting my problem since it would
be a little bit of a project for to obfuscate proprietary data.

Once again, thank you all who replied to my question! Very educational.

Aaron Fude

Barry Pearson said:
Aaron said:
Hi,
I'm sure that this is a common problem so there's probably a source
with all the answers that I want.

I find that my width attribute in td and th tags is not honored - I
end up with narrower columns. This usually happens when the table has
very many colums and doesn't fit. I use css for layout so my table is
inside an absolutely positioned div - may be that's what's causing
the problem?
[snip]

Tables are inherently difficult to control. They were intended to be that way,
and to adapt to the user's viewing conditions. I believe the best thing to do
with tables is to accept that they work best when their size is hardly
controlled at all. They are for positioning material in rows & columns, not
for pixel-level sizing.

If you want to control the sizes of table cells, control the content, not the
table. Then the table will simply adapt to the content. For example:

HTML:
<td>
<div class="width1">
content of the cell goes here
</div>
</td>

CSS:
div.width1 {
width: 200px;
overflow: auto:
}

If you want a minimum width, you could use a spacer-div. Put a zero-content
div in the cell, and control its width via CSS. (It is the modern equivalent
of a spacer-GIF).

--
Barry Pearson
http://www.Barry.Pearson.name/photography/
http://www.BirdsAndAnimals.info/
http://www.ChildSupportAnalysis.co.uk/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top