|
Posted by Jukka K. Korpela on 10/30/06 07:50
Scripsit ssk:
> I want to have a table with 3 columns.
Consider a different approach. The odds are that you are using a table for
layout only and should take a more approach instead.
> The table's width is 100%.
Sounds like a layout table. For a real table, for presenting tabular data,
there's seldom any reason to ask for 100% width no matter what the canvas
is.
> 1st column's width should be 100 px.
Sounds like a layout table with navigation bar squeezed into 100 px. Don't
use px widths. You cannot know what the most suitable (to a user) font size
is, so you cannot possibly know how many pixels you need for a word.
> The other 2 columns are variable-width but they should be the same.
You _could_ use
<table border width="100%" style="table-layout: fixed">
<tr><th width="100">foo</th><th>bar</th><th>barbar</th></tr>
etc.
You don't set widths for other rows, since the widths are calculated from
the widths of the first row cells anyway, due to table-layout: fixed. A
browser would divide the remaining width evenly between the 2nd and the 3rd
column.
As usual, usual caveats apply, but this works even on rather old browsers
like IE 6. (Whether it works depends mainly on browser support to the CSS
property table-layout.)
The usual caveats include the principle that CSS often works when you
wouldn't actually want it to work if you knew all the facts. Using
table-layout: fixed and setting the width of a column to 100 pixels (in CSS
or in HTML), you _really_ get (on conforming browsers) a 100 pixels wide
column, even if this means brutally cutting (procrusteanating) the content
of a cell. Try this with
<th width="100">Supercalifragilisticexpialidocious</th>
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
Navigation:
[Reply to this message]
|