Click here to get back home

Freezing the width of TABLE cells

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Freezing the width of TABLE cells gentsquash 06-20-2008
Posted by gentsquash on June 20, 2008, 1:12 pm
Please log in for more thread options
(If my question is too much CSS, please point me elsewhere
and I'll post there. My tests have been on Firefox on MacOS,
and I'd settle for just getting this to work there.)

I'm writing a game in javascript (but JS plays little role
in the question) for an algebra class I'll be teaching.
The playing board is a particular <table>, and each cell is
supposed to be, say, 21px wide. Unfortunately, the
cell-widths shrink when the user lessens the width of the
browser-window (the "canvas"?). One can pretend that the
cells have no content; the cell's BGCOLOR is used for the
play of the game.

What I'd prefer, when the user shrinks the canvas, is just
that the board stick off the canvas's righthand side.

I've tried <td width="21px"> and
<td style="width: 21px; min-width: 21px;">
unsuccessfully. I've also tried attaching

min-width: <total-width of table>

to various elements, e.g, each <tr> or <tbody> or <table>, to
no effect. It *did* work when I attached min-width to an
enclosing <div>, but this adversely affected other stuff in
the <div>. In any case, the table-width changes dynamically
with the play of the game, since the number of columns
change. What is supposed to be invariant is cell-width.

(Aside: The page has several nested DIVs and TABLEs, and
these may have affected my tests.)

Posted by Jukka K. Korpela on June 20, 2008, 4:37 pm
Please log in for more thread options
Scripsit gentsquash@gmail.com:

> (If my question is too much CSS, please point me elsewhere
> and I'll post there.

You are supposed to know or find out where to post. But you're excused
in this case, since the problem can be seen as an HTML problem, even
though the solution is in CSS.

> My tests have been on Firefox on MacOS,
> and I'd settle for just getting this to work there.)

Oh my. Should I stop then? You apparently have no WWW authoring problem
then. But I'll pretend that I didn't read the above.

> The playing board is a particular <table>, and each cell is
> supposed to be, say, 21px wide.

Why do you suppose so? For all that you can know, 21px may not be
sufficient for a single character, in the smallest font size that the
user can read.

> Unfortunately, the
> cell-widths shrink when the user lessens the width of the
> browser-window (the "canvas"?).

That may happen. Allocation of widths to columns is known to vary in
browsers, and width settings are often treated just as suggested widths
(which is actually what HTML specs say about them).

> One can pretend that the
> cells have no content; the cell's BGCOLOR is used for the
> play of the game.

That's poor approach. What will happen, for example, when background
colors are not used, due to browser settings or other factors?

Why didn't you post a URL? We can only see that you are hitting your
head on the wall, not what you are trying to accomplish.

> What I'd prefer, when the user shrinks the canvas, is just
> that the board stick off the canvas's righthand side.
>
> I've tried <td width="21px">

That's incorrect markup. Browsers generally ignore the px part there,
but it's still incorrect. It's not a good idea to do things wrong just
because it does not always crash a page and it isn't much more difficult
that doing things right.

> What is supposed to be invariant is cell-width.

If you really wanted the cell to be empty, which is a wrong thing to
want, you could put a transparent single-pixel image there, stretched to
the width of 21 pixels:
<td><img alt="" src="transp.gif" width="21" height="21"></td>

But the real answer is to use simple CSS. For example, use <table
class="board"> in markup and a style sheet like

.board { table-layout: fixed; }
.board td { width: 21px; padding: 0; }

> (Aside: The page has several nested DIVs and TABLEs, and
> these may have affected my tests.)

Surely. And your other problems too. Nested tables are mostly just a
quick way to create problems, rather than solve them.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Posted by Ben Bacarisse on June 20, 2008, 4:51 pm
Please log in for more thread options
gentsquash@gmail.com writes:

> I'm writing a game in javascript (but JS plays little role
> in the question) for an algebra class I'll be teaching.
> The playing board is a particular <table>, and each cell is
> supposed to be, say, 21px wide. Unfortunately, the
> cell-widths shrink when the user lessens the width of the
> browser-window (the "canvas"?). One can pretend that the
> cells have no content; the cell's BGCOLOR is used for the
> play of the game.
>
> What I'd prefer, when the user shrinks the canvas, is just
> that the board stick off the canvas's righthand side.
>
> I've tried <td width="21px"> and
> <td style="width: 21px; min-width: 21px;">
> unsuccessfully. I've also tried attaching
>
> min-width: <total-width of table>
>
> to various elements, e.g, each <tr> or <tbody> or <table>, to
> no effect. It *did* work when I attached min-width to an
> enclosing <div>, but this adversely affected other stuff in
> the <div>. In any case, the table-width changes dynamically
> with the play of the game, since the number of columns
> change. What is supposed to be invariant is cell-width.

Why not put an image in the cell? That will stop it from shrinking in
those browsers that prefer to do that. It can be small an invisible.

> (Aside: The page has several nested DIVs and TABLEs, and
> these may have affected my tests.)

and these may affect the solution so, as always, posting an example
URL is the best way to get good advice.

--
Ben.

Similar ThreadsPosted
Table with 100% width but relative cells? June 1, 2005, 11:08 am
HT make table data cells equal in width? May 9, 2007, 9:00 pm
img table cells next to each other without a gap possible? May 26, 2006, 10:27 pm
fixed table cells January 23, 2007, 11:40 pm
Table cells change size March 1, 2005, 9:02 pm
DIVs inside table cells? April 13, 2008, 9:46 am
Newbie: Problems with table cells & colspan August 9, 2004, 7:11 pm
There is no gap between cells in html table with CELLSPACING greater than zero August 25, 2004, 11:38 am
Optimized table with fixed size cells? February 4, 2007, 5:17 pm
how to properly hide/show table cells? January 31, 2008, 5:38 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap