Colspan>1 width redistribution
TD with colspan>1 redistributes its min/max/percent widths to the spanned cells.
Creating explainable tests with percentage cells is complicated. Cell's percentage cannot be observed directly, but must be inferred from td+table widths. Rules that govern relationship between table grid width and percentage cell width are:
- Rule#1, Each percentage column sets the floor for maximum table width. That table width is column.min_width / column.percent * 100.
Ex: 20px wide column, with 20% width, implies that the entire table must be at least 100px wide.
- Rule#2, Sum of all percentages, combined with sum of widths of all non-percentages sets the floor maximum table widths.
Let P% be sum of all percentages, and Fpx sum of widths of all non-percentage columns. Maximum table width = Fpx * (1 + (100-P%)/P%).
Ex: if percentage columns are 20%, and non-percentage columns are 100px, implies that that 80% is at least 100px, and that the entire table is at least 125px.
Test design
All examples have border-spacing:8, td.padding:0.
Tests are mostly tables with 2 rows. 1st row are the columns, 2nd row is the colspan>1 column being distributed. Most test's colspan>1 cell colspan encloses all cells except the last one. Each test is accompanied by test description. Test description contains:
- First line describes the test geometry: cell:css/min/max. C1:20%/20px means width:20%, intrinsic min width 20px. If max is omitted, min == max.
- Second line describes algorithm being tested in detail
- Third line describes computation that generates the result.
- Red paragraphs are major browser disagreements
Colspan>1 cell's percentage distribution auto tables
Rules
- Percentages can only be redistributed to non-percentage cells.
- If percentage does not get redistributed, treat colspan>1 cell width as Auto
- If all columns are empty (no max width), redistribute percentage evenly.
C0:10%/20px C1:10%/20px C2:auto
No colspan>1 cells, shows what table looks like without colspan>1 cell distribution.
Table width by rule#1, 20px/0.1(10%) + 4*8 => 232px. Excess table width is distributed to auto cell.
Colspan>1:40%/Auto C0:10%/20px C1:10%/20px C2:auto
Percentage does not get redistributed because all columns are percentages.
Table width by rule#1 same as previous example.
Colspan>1:20%/100px C0:Auto/0 C1:Auto/0 C2:Auto/Auto
Percentage gets redistributed evenly to empty cells.
Each cell gets 10%, then (100-8)/2=>46px min width. Table min width is 46/0.1(10%) + 4*8 => 460 + 32 => 492
Chrome Legacy is wrong, 1st span cell gets all the width. FF/Edge agree.
Colspan>1: 19%/200px colspan>1 cell, C0: 20%.20px, C1: 80px/80px
Percentage is not getting redistributed, because column% > colspan>1%
Colspan>1 cell's percentage distribution fixed tables
Colspan cells distribute width over col widths.
Rules
- Percentages are not distributed to fixed columns.
- Percentages are not distributed to percentage columns.
- Percentages are distributed to auto columns, each column gets distributed%/colspan percent.
Auto column distribution
auto colums get percentage widths distributed evenly.
C0/C1 become 25% columns.
Assignable table size is 400-4*8=368. Column size is 25% of 368 = 92px
FF disagrees in how border-spacing is handled and ends up with slightly different cell widths.
Fixed column distribution
fixed columns do not get percentage distribution.
Percentage column distribution
percentage columns do not get percentage distribution.
Distribute over percentage/auto/fixed mix cells
Collspanned TD distributes 50%. Auto TD gets 50%/(colspanned span = 4): 12.5%
12.5%* 400px is 50.
Colspan>1 cell's minimum width distribution
All unconstrained columns
Colspan>1: Auto/300px C0:Auto/75pxpx C1:Auto:25px; C2:20px/Auto
Basic distribution over auto columns, cells grow evenly.
Distribute 300-8=292 proportional to maxwidth. C0 gets 75/100*292=219.
Colspan>1: 260px/300px C0:Auto/100px C1:Auto/100px C2:Auto/Auto
Colspan>1 cell min width wins over css width.
Table width same as previous example.
All fixed columns
column gets min_width proportional to its max width.
Colspan>1: 260/300 C0:100/50/100 C1:100/100 C2:20/Auto
Distribute surplus proportional to max width.
Colspan>1 is distributing 292, surplus 92, each column gets 46.
Colspan>1: 300/300 C0:100/25 C1:100/75 C2:20/Auto
Column minimum width is less than its CSS width.
Just like last example, both columns get 46.
Colspan>1: 300/300 C0:20/100 C1:100/75 C2:20/Auto
First column's min width > css width.
Like last example, each column minimum width increases in proportion to the max.
Chrome differs from FF/Edge. It distributes min-width in proportion to css width, not max width
20/100px |
40/100px |
x |
300px min |
All percent columns
- min width never gets smaller than it started.
- min width becomes cell.percent/cells.percent * colspan>1_cell.min_width
- max width becomes cell.percent/cells.percent * colspan>1_cell.max_width
Colspan>1:Auto/300px C0:25%/50 C1:25%/30 C2:20/Auto
Colspan>1 min width gets distributed proportional to percentage (not min/max width).
Columns get min_width = 146, causes table width of 146/0.25 + 4*8 = 616.
25%/50 |
25%/30 |
x |
300px min |
Colspan>1:Auto/400px C0:20%/50 C1:60%/50 C2:20/Auto.
Colspan>1 min width gets distributed proportional to percentage (not min/max width).
Cells get 98/294, table by rule#1 98px/0.2 + 32 = 522
Edge disagrees, table is 870
20%/50px |
60%/50px |
x |
400px min |
Colspan>1:Auto/468 C0:50%/150 C1:30%/150 C2:20/Auto
This tests conflict resolution where min-width > redistributed min width.
Colspanned redistribution: distributed 468-8 = 460 over C0/C1
Colspanned 468px needs to distribute 460px over C0/C1.
C0 percent size is 50% * 460 = 230
C1 percent size is 30% * 460 = 138, defaults to min size of 150
Column 1 size is 230 + 50%/80% * 80 = 280px
Column 2 size is 150 + 30%/80% * 80 = 180px
Column 3 remains 20px
Assignable table inline size
C1 dominates estimate: 180/30% + 4*8 = 632
Compute final column widths from assignable table size:
C0 = 50% of 600 = 300 C1 = 30% of 600 = 180 , C2 gets the remaining 120
50%/150px |
30%/150px |
x |
408px min |
Colspan>1:Auto/400px C0:50%/75px/125px, C1:30%/75px/125px C2:20px/Auto
Colspan>1 cell distribution over different percentages.
400-8px min width gets redistributed as 245/147 (no min width limits)
Edge is different, table is 685 instead of 522.
50%/75 /125 |
30%/75 /125 |
x |
400px min |
Auto/fixed mix columns
Colspan>1: Auto/500; C0: Auto/40 C1:150/100
Colspan>1 excess min: 500-140-8=352; excess max: 500-190-8=302
Initial min/max C0:40/40, C1:100/150
Excess is distributed to Auto C0:392/342, C1:100/150
Assignable width is 492. C0 gets 342, C1 get max:150
Chrome Legacy does something very different to arrive at the same answer.
Initial min/max is the same.
Min gets distributed to C0 and C1 in proportion to max_width: C0:342/40 C1:150/150,
Min also gets clamped to css width. This is the key difference betweeen NG
and Legacy code. NG cannot clamp to css width, because it is not available.
Max gets distributed to both in proportion to max_width: C0:342/103 C1:150/389
Assignable table width is: 492 (sum of min), min gets used as final width.
Analysis: colspan>1 cell distribution over fixed/auto.
Legacy incorrectly distributes minmax over both fixed and auto cells
in proportion to max width,and clamps min to css width.
This width becomes final width for auto tables without any further distribution.
FF distributes min only over auto, and max over auto.
Final distribution uses Guess 2 rules: start off with Auto(min), Fixed(max),
distribute excess to Auto. Ends up with the same result as Legacy.
C0:70/Auto C1:70/Auto C2:Auto/50
This testcase demonstrates how Legacy Chrome handling of min widths is broken.
There are 2 fixed columns, and 1 auto. The width of fixed columns should be
the same, but is not. The problem happens when min-width of fixed columns is
less than fixed width, and there are auto columns.
Chrome Legacy incorrectly assigns minimum width to C0/C1
to css width of 70. It does compute assignable table width correctly
as 166 px. This violates the invariant:
assignable table width >= sum of min widths.
Chrome resolves invariant violation by truncating one fixed width column
below its minimum width.
Percentage/fixed mix columns
The Legacy code that deals with this is confusing, it tries to redistribute minimum width in proportion to max width, unless there are auto cells. All the browsers disagree on final widths. Some things everyone agrees on:
if there are auto cells, fixed cells do not grow.
Colspan>1:N/A C0:60%/100 C2:100/100
An example what table looks like without colspan>1 distribution.
Table width by rule#2: (60/(100-60) +1) * 100 = 250 + 24 = 274
Colspan>1:N/A C0:50%/100 C1:50%/100 C2:100/100
Total column percent is 100%, forcing maximum table grid width by rule #2 to infinity.
Table css width is 1px, overriding grid max width.
Final column width is column's minimum width.
Colspan>1:N/A C0:50%/100 C1:50%/100 C2:100/100
Same example as above, but table width is auto.
Table grows to size of containing block.
Colspan>1: Auto/200px C0:40%/20 C1:50/50 C2:100/20
Table css width is 1px. This forces grid minimum.
FF: %ge cell gets its percentage width resolved wrt distributing cell.
fixed cells get remaining excess width redistributed in proportion
to max size.
Chrome algorithm: distributes proportionally to min_width. The problem with
this is that 40% cell will end up with 0 if no min width.
Edge distributes all the width to the %ge cell, Chrome distributes proportionally to min width.
Colspan>1 cell's maximum width distribution
Only constrained colspans can distribute max-width over fixed columns
Colspan: constrained. Col: constrained
Constrained colspan redistributes widths over constrained cols.
Colspan: unconstrained. Col: constrained
Colspan max-width does not get redistributed.
Colspan: unconstrained, Col: constrained/%
Colspanned col distributes width over %ge column.
max-guess is 50px + 200px*50% = 150px
distributable_size is 50px
%ge column gets percentage_size + distributable_size = 150px
Later, this makes table 300px wide.
FF, Legacy, and TablesNG all disagree about the correct widths. FF feels more like the right answer, but I can't figure out the math behind it.
Merging cell widths into column widths
What happens when different types of cells get merged into a single column?
C0:0 25%/50px C0:1 50%/40px
C0:0 alone would imply table width of 50/.25 = 200px.
C0:1 alone would imply table width of 40/.5 = 80px.
But, largest percentage and largest min width win, so the table width is 50/.5 = 100px.
25%/50px |
Auto |
50%/40 |
Auto |
Merging fixed and percentage
Column that contains both percent and fixed cells is treated as percent.
25%/100 |
50px fixed |
auto |
150 |
Auto |
Auto |
Order of colspan>1 cell redistribution
Initial minmax of all cells is 50px.
C0:1 redistributes 200
C1:2 redistributes 400
Chrome distributes right-to-left:
C1:2 distributes 400, and C1 and C2 both get 200
When C0:1 turns come, C0+C1 are already long enough, nothing to distirbute
In testcase /tables/mozilla_expected_failures/core/col_span2.html
distribution right-to-left is described as a bug.
Firefox and Edge both distribute left to right.
Chrome is only one that distributes right to left.
Firefox distribution is not cumulative, it uses original minmax to compute final widths. Edge agrees with TablesNG.
But, mozilla is stable for row reordering.
200 |
50 |
50 |
400 |
Auto |
Auto |
Auto |
400 |
50 |
50 |
200 |
Auto |
Auto |
Auto |
Order of colspan>1 cell redistribution
Similar to previous testcase, but colspan is 3, not 2.
In testcase /tables/mozilla_expected_failures/core/col_span2.html
distribution right-to-left is described as a bug.
Firefox and Edge both distribute left to right.
TablesNG matches Edge/FF.
300 |
50 |
50 |
600 |
Auto |
Auto |
Auto |
Auto |