On 2013-05-18 18:47 dorayme wrote:
> ...
> Well, COLSPAN is for the purpose of spanning cells from row to row so
> that the author can keep the *rows themselves* within a table equal
> width. Your making the tables a definite width (40em) actually results
> in your cells in your second row in the second table not 10em each (as
> specified in the CSS) but whatever is needed to make the table 40em
> with four cells. The browser takes over and forces the resolution of
> the seeming conflict in favour of your table width (I mean, one can at
> least conceive it might ignore it instead and do something else you
> don't want- like in the first table).
You are right about the table width. Without that specification the
table is only a little wider, and with it you allow room for browser
interpretation. I had used table width at the phase when I was trying to
make the code work the way I wanted it to. It is clearly unnecessary.
But the main issue is that (a) without specifying colspan="2", the
default colspan="1" forces the cells to align one under the other, which
is as they should do usually, though not in my case. (b) With
colspan="2" (or more) and without specifying cell widths, the cells are
again aligned properly, as in the Pointed Ears' diagram in message
above, which is the typical use of colspan. These 2 uses I learned a
long time ago. What I just realized is that (c) when you specify cell
widths *and* use colspan="2", you can have rows with cells of varying
widths.
I am sure there may be limitations to this method, but it works in my
case and it will take some experimentation with different cell widths
and different browsers to find out what they are. But with my method it
seems to me that it should be possible to have cells of varying widths
on different rows, as for example in charts with horizontal bars.
Below is the code of 2 tables both with specified cell widths and using
colspan="2"; table width though is specified only in table 1 but not in
table 2. Clearly table 2 is preferable since it allows less space for
browser interpretation, unless there is some particular reason to resize
the table to a specific width.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>table</title>
<style type="text/css">
body {
background-color: black;
color:white;
}
table {
margin: auto;
border: 2px solid white;
}
td {
border: 1px solid white;
text-align: center;
width: 10em; /* default */
}
table td.hlf { width: 5em; }
table.t1 { width: 40em; }
</style>
</head>
<body>
Table 1: with colspan="2", table width: 40em;
<table class="t1">
<tr>
<td class="hlf">1</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td class="hlf">1</td>
</tr>
<tr>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
</tr>
</table>
Table 2: with colspan="2", without specified table width
<table>
<tr>
<td class="hlf"></td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td class="hlf"></td>
</tr>
<tr>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
</tr>
</table>
<body>
</html>
Cheers,