473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiple variable-width columns in a table

I have a problem that can be simplified to the following: I have a
table with three columns. I need the middle column to be fixed width,
let's say 100px. The other two columns I want to be variable width,
such that one (say the left column) will minimize its width to the
smallest it can be while still fitting a short line of text (no more
than 32 characters) on a single line with no breaks. The right column
I would then want to maximize its width to the remainder of the width
on the screen.

My current solution is as follows:

<table width="100%" border="1" cellpadding="0px"
cellspacing="0px"><tbody><tr><td>
Minimize
</td><td style="width:100px; min-width:100px; ">
Fixed
</td><td style="width:100%; ">
Maximize
</td></tr></tbody></table>

It works in everything but IE (as usual), which doesn't preserve the
fixed width column. Is there a better solution, and if not, how do I
fix this in IE, aside from the natural inclination to direct all IE
users to a page that says "IE sucks".
Sep 27 '08 #1
2 14709
bgold12 wrote:
I have a problem that can be simplified to the following: I have a
table with three columns. I need the middle column to be fixed width,
let's say 100px. The other two columns I want to be variable width,
such that one (say the left column) will minimize its width to the
smallest it can be while still fitting a short line of text (no more
than 32 characters) on a single line with no breaks. The right column
I would then want to maximize its width to the remainder of the width
on the screen.
Even though the idea is simple, it is challenging, since table layout is so
problematic - with browser differences, oddities, and quirks. Moreover, the
idea is not expressible in HTML at all. As fas as I can see, it is not
expressible even in CSS. You can of course express the idea of fixed width
for a column in a sense, but only in a sense. In HTML, <td width="100">
(which you don't use in your code fragment and which wouldn't help in
practice) specifies a suggested _minimum_ width. In CSS, you can say width:
100px, but as you can see, IE won't always obey it. Part of the reason is
that you are also suggesting 100% width for one cell, so your suggestions do
not constitute a coherent set.
My current solution is as follows:
Even in a simple case, it is best to provide a URL, if only to show a good
example.
<table width="100%" border="1" cellpadding="0px"
cellspacing="0px"><tbody><tr><td>
The markup is incorrect, since HTML attributes must not contain the px unit.
In practice, browsers will ignore it, but it's still incorrect.
Minimize
</td><td style="width:100px; min-width:100px; ">
Fixed
</td><td style="width:100%; ">
Maximize
</td></tr></tbody></table>
So how do you expect browsers to deal with
100% = something + 100px + 100%
? The surprising thing is that some browsers do what you want.
It works in everything but IE (as usual), which doesn't preserve the
fixed width column. Is there a better solution, and if not, how do I
fix this in IE, aside from the natural inclination to direct all IE
users to a page that says "IE sucks".
Such redirection a very good idea at least from the perspective of your
competitors. :-)

Seriously, using inner markup in the middle-column cell seems to help:

<td><div style="width: 100px">...</div></td>

The point is that this sets a minimum width for the contents of the cell.
This will effectively deal with the allocation of width outside the table
layout algorithm, so that the cell content is comparable to an image or
other fixed-size element.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Sep 27 '08 #2
On 2008-09-27, bgold12 <bg*****@gmail.comwrote:
I have a problem that can be simplified to the following: I have a
table with three columns. I need the middle column to be fixed width,
let's say 100px. The other two columns I want to be variable width,
such that one (say the left column) will minimize its width to the
smallest it can be while still fitting a short line of text (no more
than 32 characters) on a single line with no breaks. The right column
I would then want to maximize its width to the remainder of the width
on the screen.
This may be your best bet:

table { width: 100%; }
#left { width: 1px; white-space: nowrap }
#middle { width: 100px; }

<table border=1>
<tr>
<td id="left">
Minimize
</td>
<td id="middle">
Fixed
</td>
<td id="right">
Maximize
</td>
</tr>
</table>

I don't have IE to test it in. If white-space doesn't work in IE
consider non-standard-but-who-cares <nobrinside the first td.

1px makes the left column as narrow as possible, which means as wide as
the longest word.

The middle is 100px, and the right should take up the rest because the
whole table is 100% and there's nowhere else for the width to go.

Automatic table formatting is not precisely and accurately specified
anywhere, so keep it simple. Avoid asking for the logically impossible
(one column 100px and another 100% for example) because that just takes
you deeper into the woods-- "ab falso quod libet".
My current solution is as follows:

<table width="100%" border="1" cellpadding="0px"
cellspacing="0px"><tbody><tr><td>
Minimize
</td><td style="width:100px; min-width:100px; ">
Fixed
</td><td style="width:100%; ">
Maximize
</td></tr></tbody></table>

It works in everything but IE (as usual), which doesn't preserve the
fixed width column. Is there a better solution, and if not, how do I
fix this in IE, aside from the natural inclination to direct all IE
users to a page that says "IE sucks".
It may think you want 100% more than you want 100px. It can't really be
blamed for that since you asked for both.
Sep 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DrewM | last post by:
I'm still thinking about session variables :-) Does anyone know the detail of how session variables are actually stored? The question I'm trying to answer is: Is it more efficient to store and...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
5
by: Charles L | last post by:
Can someone explain to me what the following means? "C permits multiple definitions of a variable in any given namespace, provided the definitions are the same and it generates only a single...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
12
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for...
14
by: Carramba | last post by:
hi! I have program with several funktion witch are in separete files, I have one include file were I have definet some variables and initiated 'const double fVar=0.874532;' this files is includet...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
15
by: Iced Crow | last post by:
In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures... How do I do this in VB? I only know of assigning...
11
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.