473,569 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

width in table

Hi,

Maybe this is a simple question, but I can't seem to get it to work.
Let's say I have this table:

<table style="width: 300px">
<tr>
<th>Header</th>
<td>1</td>
<td>22</td>
<td>333</td>
</tr>
</table>

How can I use CSS 2 to make the th take minimal width and let the other
columns divide the rest of width equally. Also I do not know how many
data columns I have.
Jul 21 '05 #1
9 6695
Robert <ro****@noreply .x> wrote:
Maybe this is a simple question, but I can't seem to get it to work.
Let's say I have this table:

<table style="width: 300px">
<tr>
<th>Header</th>
<td>1</td>
<td>22</td>
<td>333</td>
</tr>
</table>

How can I use CSS 2 to make the th take minimal width and let the other
columns divide the rest of width equally. Also I do not know how many
data columns I have.


http://homepage.ntlworld.com/spartanicus/robert.htm

Note that it's hard to imagine a valid reason to fix the width of a
table, especially when using the px unit and when the content contains
text. If the table is used for layout purposes then the correct answer
is stop doing that.

--
Spartanicus
Jul 21 '05 #2
Robert wrote on 26/04/2005 :
Hi,

Maybe this is a simple question, but I can't seem to get it to work.
Let's say I have this table:

<table style="width: 300px">
<tr>
<th>Header</th>
<td>1</td>
<td>22</td>
<td>333</td>
</tr>
</table>

How can I use CSS 2 to make the th take minimal width and let the other
columns divide the rest of width equally. Also I do not know how many data
columns I have.


as you dont know the amount of columns you will have, I am guessing
that these are built dynamically. is that correct? if so, then perhaps
you could do a litle run-time width calculations... .
<psuedo_sorta_c ode>
var_width = 100 / (var_column_cou nt + 1) ; // add one for the <th>
write the var_width to the width placeholder in the HTML template.
(perhaps search_replace the var_width placeholder.
</psuedo_sorta_co de>

your HTML template may look like this.

<table style="width: 300px">
<tr>
<th style="width:{v ar_width}%;">He ader</th>
<td style="width:{v ar_width}%;">1</td>
<td style="width:{v ar_width}%;">22 </td>
<td style="width:{v ar_width}%;">33 3</td>
</tr>
</table>

--
a beef jerky site http://www.choicebeefjerky.com.au
not a beef jerky site http://mycoolwheels.com/vote.cmks
nobody ever dreams of working for the man

Jul 21 '05 #3
Spartanicus wrote:
Robert <ro****@noreply .x> wrote:

Maybe this is a simple question, but I can't seem to get it to work.
Let's say I have this table:

<table style="width: 300px">
<tr>
<th>Header</th>
<td>1</td>
<td>22</td>
<td>333</td>
</tr>
</table>

How can I use CSS 2 to make the th take minimal width and let the other
columns divide the rest of width equally. Also I do not know how many
data columns I have.

http://homepage.ntlworld.com/spartanicus/robert.htm


This only works if the number of TD columns are exactly 3.
Note that it's hard to imagine a valid reason to fix the width of a
table, especially when using the px unit and when the content contains
text.
Because I like the other tables I generate to be of equal size.
If the table is used for layout purposes then the correct answer
is stop doing that.


No, it's not for the layout of images or something like that.
Jul 21 '05 #4
Disco Octopus wrote:
as you dont know the amount of columns you will have, I am guessing that
these are built dynamically. is that correct? if so, then perhaps you
could do a litle run-time width calculations... .


Yes I thought about this too. Just was hoping to let CSS work this out
automatically. I guess my expectations for CSS were too high :)
Jul 21 '05 #5
Robert wrote:
Disco Octopus wrote:
as you dont know the amount of columns you will have, I am guessing
that these are built dynamically. is that correct? if so, then perhaps
you could do a litle run-time width calculations... .

Yes I thought about this too. Just was hoping to let CSS work this out
automatically. I guess my expectations for CSS were too high :)


Your expectations weren't too high, they were wrong.
CSS is about style not about calculating.

RW
Jul 21 '05 #6
Rob_W wrote:
Robert wrote:
Disco Octopus wrote:
as you dont know the amount of columns you will have, I am guessing
that these are built dynamically. is that correct? if so, then
perhaps you could do a litle run-time width calculations... .


Yes I thought about this too. Just was hoping to let CSS work this out
automatically. I guess my expectations for CSS were too high :)

Your expectations weren't too high, they were wrong.
CSS is about style not about calculating.


Having to divide the width between columns is style.
Jul 21 '05 #7
Robert wrote:

How can I use CSS 2 to make the th take minimal width [...]

th {width: 0%;}
--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Jul 21 '05 #8
Robert wrote :
Rob_W wrote:
Robert wrote:
Disco Octopus wrote:

as you dont know the amount of columns you will have, I am guessing that
these are built dynamically. is that correct? if so, then perhaps you
could do a litle run-time width calculations... .

Yes I thought about this too. Just was hoping to let CSS work this out
automatically. I guess my expectations for CSS were too high :)

Your expectations weren't too high, they were wrong.
CSS is about style not about calculating.


Having to divide the width between columns is style.


Indeed, but doing the actual dividing to work out what the width should
be, is not style.

--
a beef jerky web site : http://www.choicebeefjerky.com.au
not a beef jerky web site : http://mycoolfish.com/vote.cmks
dont pick your nose if it is sore

Jul 21 '05 #9
Disco Octopus wrote:
Having to divide the width between columns is style.

Indeed, but doing the actual dividing to work out what the width should
be, is not style.


If I set the width to a certain percentage there needs to be some
dividing too. To have the ability to set a relative 'weight' does not
make those calculations much harder. Well... it sure would be very
useful I think.
Jul 21 '05 #10

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

Similar topics

7
12179
by: Graham J | last post by:
Apologies for the partial post that mysteriously escaped as I was composing. I shall try again. For many years I have been happily and successfully coding tables such that the WIDTH specified in a TD is the complete column width including any CELLPADDING. For example for a 400 pixel wide table with four 100 pixel wide columns and 10 pixel...
4
26202
by: N. Demos | last post by:
The following code renders as intended in IE (A TABLE, with cells of fixed width and height, inside of a DIV with fixed width and height and overflow set to hidden.) In Firefox, the table cells assume a narrower with than specified. If I comment out the width for the DIV, then the cells render with the correct width and height. Why is this...
0
3061
by: javaguy | last post by:
I have a table I hide show/hide through a pair of divs. The show/hide part works fine in both Mozilla and MSIE. When switching between the hide and show versions the Mozilla browser keeps them in small width, about 740 pixels. When switching between show/hide with MSIE the "show" table wants to display about 960 pixels. If I set the...
4
6143
by: Alex Meier | last post by:
I have the following problem: I need a simple, tabular layout in a webshop. - left column: navigation column with approx. 170px width - right column: content area the goal: the left column should contain a few "boxes" (these are HTML- tables) which should be all of the same width. So, I attributed the left column with 'width="170"' and...
5
169717
by: Jean Pion | last post by:
Dear readers, Can anyone explain how to set column width of a table in ccs. I use the following style in an external stylesheet: table.tbl { table-layout:fixed; border-top: 5px solid #333; border-collapse: collapse; background: #fff; width: 95%} table.tbl td { border-bottom: 1px dashed #33ccff; padding: 2px 5px; text-overflow:ellipsis;...
2
1450
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild, AppendChild, making width grow? Hi,
11
3560
by: Norman L. DeForest | last post by:
Am I misunderstanding the CSS specifications or is Firefox (version 1.0.6) (and Opera) doing the wrong thing? It appears that Firefox 1.0.6 includes the border in width calculations for tables but not in height calculations. Oh, and Opera version 8.02 does the same thing. |<-->| |<-->| <------ border |<------------>| ...
2
10385
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat actually happens is... when the Text size is too big... the column
5
11012
by: Taras_96 | last post by:
Hi everyone, Can anyone tell me why the top paragraph block stretches across the screen (as you would expect), while the bottom div doesn't stretch across the entire screen? When I set the width to 100% (which I interpret as saying 'make this width the same width as the parent (which is the entire screen)) the div is made just wide enough...
10
5415
by: magnesium | last post by:
I have this under-construction page, If you try and select the link coming from the bottom with your mouse, you'll notice, that before the actual link is selected, the td background will change. you have to the select the text itself to make the link select. I don't know If I've explained it well... I tried height:100%, and width:100%; in the...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.