Skip to content

[css-tables] Calc for table layout #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomalec opened this issue Feb 2, 2016 · 15 comments
Closed

[css-tables] Calc for table layout #94

tomalec opened this issue Feb 2, 2016 · 15 comments

Comments

@tomalec
Copy link

tomalec commented Feb 2, 2016

Are there any plans to specify calc behavior for widths and heights in table layout?
Implementations varies across browsers (http://jsbin.com/juqafi/1/edit?html,css,output)

Given the complexities of width and height calculations on table cells and table elements, math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables MAY be treated as if auto had been specified.

I suspect the complexity of the math grows when it comes to mix unit (personally, I feel it's just a set of mathematical equations, to be solved in not more sophisticated way that sizing algorithm for Grid Layout).

However, I would say that expressions like:

Should be really easy to compute, resolve, and apply.

@tomalec tomalec changed the title calc for table [css-values] Calc for table layout Feb 2, 2016
@miyconst
Copy link

miyconst commented Feb 2, 2016

+1

@tabatkins
Copy link
Member

The Tables module is now receiving some love, so we'll see!

I agree that there are some "trivial" calc()s that should be possible without making anything complicated, but because of that, they're also avoidable. It's easier to write calc(100% / 7) than 14.28%, but the diff isn't huge either.

@FremyCompany
Copy link
Contributor

I don't think this is reflected in the latest CSS Tables draft, but some investigations on this exact topic were conducted by yours truly.

The sad conclusion is that there is probably no way to allow what you want in a way that would work continuously, as width:0% and width:0px have very different behaviors. Heck, even width:10% can have a different behavior than width:10% if specified on consecutive but otherwise perfectly identical column, tables are a complete mess. CSS Grids resolve width distribution in a way that makes it possible to seamlessly mix units, but CSS Tables don't.

I feel no difficulty in supporting calc expression resolving to only one particular unit, but that might mislead authors in believing that calc is entirely supported.

I do not entirely discard the idea of making calc work, but I suspect this cannot make the cut for our current level of the spec, because we would need to add a few new features which is against the spirit of the spec right now, which would add fluidity to the currently one-or-zero behavior of the width distribution. We have so many challenges on that topic already...

@FremyCompany
Copy link
Contributor

Btw, just so you know, mixing units does not work even for one column. It just happens that since you only leave one column unconstrained, it takes the size remaining after you assign its width to the other columns. You can try changing the value as much as you can, it should not have any effect. If it does in some browser, let me know.

@tomalec
Copy link
Author

tomalec commented Feb 23, 2016

Thanks for your responses :)

It's easier to write calc(100% / 7) than 14.28%, but the diff isn't huge either.

I feel no difficulty in supporting calc expression resolving to only one particular unit, but that might mislead authors in believing that calc is entirely supported.

Supporting calc for non-percentage values, and not supporting it for % is misleading anyways. Even more, "MAY be treated as if auto had been specified" and making behavior different across browsers gives even more confusion to the developers. Maybe, if it's not going to be supported precisely, changing it to "SHOULD" would make it cleaner and more predictable.

CSS Grids resolve width distribution in a way that makes it possible to seamlessly mix units, but CSS Tables don't

The funny thing is that I discovered this issue as CSS Grid is not supported by browsers yet. So I was trying to mimic its behavior by custom element that uses Shadow DOM content distribution and Table Layout.

What about forcing it by table-layout?

Currently, (in Chrome only) setting table-layout: fixed; makes in this particular case width: calc(10px + 50%) works (http://jsbin.com/juqafi/2/edit?html,css,output). I feel that setting it to fixed could mean "Disregard any automagical space distribution, use values I gave".

Forgive me, if lack of sleep made my fantasies to weird, but...
If cutting current spec and breaking pretty stable state is a problem, but CSS Grid does good job on solving such cases, we could make table-layout: grid. Then without breaking existing behavior of Table Layout we could use Grid-like features to style <table>?

@FremyCompany
Copy link
Contributor

This Chrome bug is being tracked in the spec:

Table-layout:fixed causes different width distribution in Chrome
https://drafts.csswg.org/css-tables-3/#bug-list

I initially saw no reason to change the sizing behavior based on the table-layout mode, because this is not at all what that property is about. The fact Chrome switches to a completely different computation mode breaks a lot of things, but of course allows other things to work that cannot work in normal tables (though I never spotted this calc subtlety, thanks for mentioning it). Author feedback is always important, and given Chrome behavior is likely web-compatible, this thread is something we may consider while deciding how to resolve the previous issue.

That being said, CSS Tables will probably not be fixed before CSS Grids is out, and no one would encourage you to rely on CSS Tables more than on a absolute requirement basis, their layout system is slow and buggy.

I will make sure to mention this thread next time we do a breakout session / f2f topic on CSS Tables, but I would encourage further discussions to happen on [email protected], the official mailing list ;-)

@fantasai fantasai changed the title [css-values] Calc for table layout [css-tables] Calc for table layout Jun 29, 2016
@gregwhitworth
Copy link
Contributor

It was resolved in the CSSWG meeting today to move this to L4 of the Values and Units spec to require resolving a calc() that contains values of the same unit.

@gregwhitworth
Copy link
Contributor

Actually, I leave this open until the change is made to L4 of units and values

@gregwhitworth gregwhitworth reopened this Jul 27, 2016
@fantasai fantasai added css-values-4 Current Work and removed css-values-3 labels Jul 27, 2016
fantasai added a commit that referenced this issue Jul 27, 2016
…ble widths and heights to only mixed-input cases. #94
@fantasai
Copy link
Collaborator

OK, I tightened this up in css-values-4 to only allow fallback to auto if the calc() expression mixes both percentages and lengths. The remaining question is about whether fixed table layout should require handling the mix, and if so if that's just for widths or also heights. (Given what fixed layout means, having it work for widths--or the inline size, rather--is perfectly reasonable.)

@gregwhitworth
Copy link
Contributor

Personally, I would prefer for them to be the same, adding additional confusion that you can mix %s with that of lengths only in layout-mode: fixed. This argument is for consistency reasons only, but I think that's a strong argument given the number of inconsistencies already in table layout.

@xiaochengh
Copy link
Contributor

For interoperability, and to reduce frictions in implementing the other proposed math functions, should we turn the "MAY" into "must"?

This issue has also been discussed in the context of min/max(), and the situation seems worse there:

With calc() alone, the value remains a linear function (to the value the % is evaluated against), which means theoretically there should still exist a "correct" intrinsic table size that allows all cells to be sized correctly. UA may choose to do that according to the current spec.

With other math functions introduced, the function is no longer linear and may not even have an inverse, which means the above is no longer possible. In such cases, UA must fall back. For interop, it would be better to specify what fallback should be taken. Turning "MAY" into "must" seems to be the easiest and most reasonable one to me.

@FremyCompany
Copy link
Contributor

Turning the MAY into a MUST sounds reasonable to me. I don't think anyone want to start investigating this more deeply, especially since as noted multiple times the existence of a solution isn't guaranteed.

There still remains the question of fixed layout where percentages can be resolved to pixels and handled as such without too much trouble for most of the algorithm. I would be open to specify that this case must work, and provide the details of how.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed Calc for table layout, and agreed to the following:

  • RESOLVED: Any math expression of a complex type is treated as auto. Simple typed things continue to work as today.
The full IRC log of that discussion <emilio> Topic: Calc for table layout
<emilio> Github: https://github.com//issues/94
<emilio> xiaochengh: So the issue is what to do with percentages and calc
<emilio> ... spec says a bunch of stuff may be treated as auto
<fremy> "Given the complexities of width and height calculations on table cells and table elements, math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables MAY be treated as if auto had been specified."
<emilio> ... I'm proposing changing the MAY into MUST
<emilio> ... it's pretty complicated if we don't treat it as auto
<fremy> q+
<emilio> ... second reason is that this is creating friction when implementing min() / max()
<emilio> ... calc() is complicated, but min() / max() make it a pretty hardly solvable problem
<emilio> ... so I propose to make this a MUST
<emilio> TabAtkins: this is what dbaron proposed back in the day
<emilio> ... and we punted min and max because of that
<emilio> heycam: implementation status?
<emilio> fremy: all browsers match the spec
<emilio> ... for normal table layout
<emilio> ... the algorithm just doesn't make it possible
<emilio> ... in fixed table layout there's one browser that supports percentages based on the size of the table
<emilio> ... as to the question of whether we should remove the behavior for normal table layout is fine
<emilio> ... for fixed layout it'd be nice to also remove it, but Chrome and Safari
<emilio> ... do respect it so it'd be nice to remove that
<emilio> ... or add to the spec that it is respected in fixed table layout and how, which should be straight-forward
<heycam> emilio: there's also the question of whether we should in presence of min and max ...
<heycam> ... Firefox uesd to treat calc(%) as auto
<heycam> ... we no longer do that
<heycam> ... but it raises the question of how min and max behave with only percentages
<heycam> ... I guess that's fine to resolve?
<heycam> TabAtkins: I don't want to special case min and max on type
<heycam> ... that's awkward
<heycam> ... having min and max work in some case if you have certain shapes of expression inside of it
<heycam> emilio: I think given the way we behave, all browsers treat calc with percentages as a percentage, we should do the same for min and max
<heycam> fremy: that sounds reasonable to me
<heycam> .... if there is a sum of % and px, after you've computed, then you decide not to do anything, follow the MUST
<heycam> ... if you have min(10%, 20%), the computed value will be 10%, so you don't have the problem
<heycam> .... I would be in favour of that wording
<heycam> emilio: what about calc(10% + 0)?
<heycam> ... that's simplifies to 10% in all browsers
<heycam> Rossen: yes we've resolved that previously
<heycam> fremy: so what about fixed mode
<heycam> ... I assume it's probably fine to apply this rule to both?
<heycam> RESOLVED: Any math expression of a complex type is treated as auto. Simple typed things continue to work as today.
<emilio> TabAtkins: https://github.com//issues/3482#issuecomment-451590359
<heycam> zoe: no objections

aarongable pushed a commit to chromium/chromium that referenced this issue Sep 30, 2019
Current progress:
- Implementation finished
- Test suite finished except for a minor serialization spec issue [1],
  which seems minor enough not to block the launch
- The spec issue with table layout [2] is already resolved. In case of
  similar spec issues in other layout algorithms, I believe a similar
  approach (UA must treat the value as auto) can be adopted.

Therefore, I believe there is no longer any issue blocking the shipping
of the feature.

[1] w3c/csswg-drafts#4372
[2] w3c/csswg-drafts#94

Bug: 825895
Change-Id: I0fe8e934d4429fa6ed1c3dd8847f70b1ba350e07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829471
Reviewed-by: Rune Lillesveen <[email protected]>
Reviewed-by: Emil A Eklund <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701148}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 30, 2019
w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
@xiaochengh
Copy link
Contributor

I've made PR #4389 for the resolution above.

PTAL, and thanks for that!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 30, 2019
w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 1, 2019
w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <[email protected]>
Reviewed-by: Aleks Totic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701597}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 1, 2019
w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <[email protected]>
Reviewed-by: Aleks Totic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701597}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Oct 14, 2019
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <[email protected]>
Reviewed-by: Aleks Totic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424
xeonchen pushed a commit to xeonchen/gecko that referenced this issue Oct 14, 2019
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <[email protected]>
Reviewed-by: Aleks Totic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 16, 2019
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Reviewed-by: Aleks Totic <atoticchromium.org>
Cr-Commit-Position: refs/heads/master{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424

UltraBlame original commit: ffa86f64139eb8d73dbbe409e9bdc3846a0951c6
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 16, 2019
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Reviewed-by: Aleks Totic <atoticchromium.org>
Cr-Commit-Position: refs/heads/master{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424

UltraBlame original commit: ffa86f64139eb8d73dbbe409e9bdc3846a0951c6
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 16, 2019
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Reviewed-by: Aleks Totic <atoticchromium.org>
Cr-Commit-Position: refs/heads/master{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424

UltraBlame original commit: ffa86f64139eb8d73dbbe409e9bdc3846a0951c6
@fantasai
Copy link
Collaborator

Seems like this was fixed, so closing out. Please open a new issue if we missed anything. :)

bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this issue May 1, 2025
…calc() in table layout, a=testonly

Automatic update from web-platform-tests
Add/Revise WPT to reflect resolution of calc() in table layout

w3c/csswg-drafts#94 made a resolution that

"Any math expression of a complex type is treated as auto. Simple typed
things continue to work as today."

This patch adds new tests and revises existing tests to reflect the
resolution.

Bug: 382725
Change-Id: I522799b51fdd4a7cfa66e137ae31c68aaf2dea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832619
Commit-Queue: Xiaocheng Hu <[email protected]>
Reviewed-by: Aleks Totic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#701597}

--

wpt-commits: cda40b6ff20c841a6195e95387d09072db8fd6e3
wpt-pr: 19424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants