Re: feat: Adding an order property for td/th or colgroup

On 6/6/22 09:03, Ulrich-Matthias Schäfer wrote:
> I recently wondered why the order property only exists for flexbox and grid. 
> Imo it makes a lot of sense for the table element as well. Sometimes you want 
> to reorder columns and other is no convenient way to do so besides changing 
> the whole dom structure.

Hi!
I filed your request into https://github.com/w3c/csswg-drafts/issues/7340 for 
tracking. That said... tables are a particularly gnarly part of most CSS 
layout engines, so I am not too optimistic that this will be picked up anytime 
soon...

> Adding an order property to td would tackle that issue. An obvious problem is 
> that you can easily create conflicts by setting different orders for tds of 
> the same column. That's why the better place to define this is probably 
> colgroup. However, it seems like the spec moved away of using colgroup at all 
> because all attributes (including width) seem to be deprecated. I find this a 
> bit strange because it allows a convenient way to define column properties. 

The attributes are deprecated because they are presentational markup (which 
doesn't belong in HTML), but CSS properties are not deprecated (because 
presentational instructions is what CSS is for). If we were to apply `order` 
to table columns, I think using <col> and <colgroup> for it would make perfect 
sense.

The main open question I think is what happens to colspanning cells:
* Suppose we have a cell spanning two columns. If their order is reversed, is 
that cell still spanning the same two columns?
* What if the first column is reordered to be the 5th column (non-adjacent)?

> Since tables are defined column-wise but are rendered row-wise, it becomes 
> hard to define column props without writing nth-child selectors all the time. 

Yes. The Selectors 4 draft has some ideas around making this easier and more 
robust: https://www.w3.org/TR/selectors-4/#table-pseudos
There's not been much interest from implementers, however. :(

> As written above, for ordering, nth-child doesn't seem to be a proper solution 
> anyway. Hiding or rearranging columns are powerful features needed in a lot of 
> rich web applications and providing an easy way to do it in CSS would be awesome.
> 
> What do you think?
`visibility:collapse` was intended to handle hiding/showing columns, fwiw. See
https://www.w3.org/TR/CSS2/tables.html#dynamic-effects

~fantasai

Received on Tuesday, 7 June 2022 20:59:49 UTC