Open frivoal opened 5 years ago
I should test in browsers just to be sure, but as far as I know, vertical-align
works on the cells at the table row level, as in: cells get aligned in the first row layout based on that, so vertical-align
does not apply in the table cell block axis but the table row block axis, just like it does for inlines in a block.
My understanding is that the thing that is special about tables is not how vertical-align works, it is that after the alignment, all cells are stretched to the full line height, where in a block>inline situation, there is empty space above/below the aligned inlines.
At this point, cell boxes that are smaller than the height of the rows they span receive extra top and/or bottom padding such that their content does not move vertically but their top and bottom edges meet the ones of the rows they span.
I guess I should clarify that vertically
in the above spec text refers to the verticality of the table row, but there is a figure just above that kinda does clarify it a bit.
Working from the row rather than the cell seems confusing to me, but maybe, that just shows I don't understand how rows and cells and vertical-align works :)
If it is working from the row's writing mode, what does it do if a cell has it's writing-mode orthogonal to the row? Say, a horizontal-tb
table with horizontal-tb
rows, with a vertical-rl
cell, and vertical-align:middle
. Assume that the table has other rows and other columns, such that this orthogonal cell ends up being bigger than it needs to in both axises. My guess was that it would be "centering" the text in the block axis of the cell, i.e. horizontally. If not:
Vertical-align works the same way for table cells in a table row as if you took all the cells of the row,
Here is an example: https://jsfiddle.net/3jp2nwoy/
The only difference is that with table rows, you add padding to the cells so that their top and bottom sides meet the full row height (without shifting their content box) while for a normal flow line, you just leave blank space on either side of the line block.
If you have boxes without background and border, are nothing positioned relatively to them, there is no difference between a table-cell row and an inline-block flow regarding how vertical-align works. Otherwise, the added padding has some impact.
Here is the same example but with support for proper background/border/etc (addition of padding-top/padding-bottom to meet the row height after alignment, assuming things have roughly the same height as on my machine):
https://jsfiddle.net/3jp2nwoy/1/
Now, you are correct that there is no way to visually center the content of an inline-block or block in its block axis if that block axis does not happen to match the parent one. That's a limitation of flows in general, not of table cells (which are more or less a block).
My impression is that what you are trying to achieve is to add a align-content
/ justify-content
on the table cell. The only problem is that those properties do not apply to regular blocks as far as I can recall, only to flex and grid. But maybe they should?
That would be an issue against another spec however. The internal layout of a table-cell is just the layout of a block, so you would want to modify css-align to interact with blocks.
cc @fantasai since she's the expert wrt css-align
I should add to the previous explanation that if some cells have height, or if the row has an height, or if there are spanning cells forcing some rows to grow, things are still a bit different wrt a flow of inline-block in the sense that there is this additional constraints that may apply. If we had to think in terms of flow, I think the impact is roughly the same as if every line started with an anonymous inline-block of width 0px and of height being the height of the imposed height, with a vertical-align of top (because cells will lower their bottom to accommodate that constraint, if I recall correctly)
Hopefully this comparison of vertical-align
between block flows and table-rows has cleared up why it does not affect the cells in their own axis and rather affect cells in the axis of the row,
This is currently defined in https://www.w3.org/TR/css-align-3/#distribution-block There's an interesting question if this is how it should work, but it is how it does per spec.
The CSS Working Group just discussed vertical-align on orthogonal table cells
, and agreed to the following:
RESOLVED: vertical-align operates in the block-axis of the table cell
RESOLVED: the inline axis of an orthogonal table cell is sized *after* the baseline alignment of the non-orthogonal cells in that row
Need clarification for implementation:
the inline axis of an orthogonal table cell is sized after the baseline alignment of the non-orthogonal cells in that row
What happens when all cells are orthogonal? Is row height defined by minimum or maximum inline size?
What are %ge inline/block sizes resolved against?
vertical-align operates in the block-axis of the table cell
vertical-align: baseline is interesting. There is no "row baseline", what does baseline alignment means here?
Need clarification for implementation:
the inline axis of an orthogonal table cell is sized after the baseline alignment of the non-orthogonal cells in that row
What happens when all cells are orthogonal? Is row height defined by minimum or maximum inline size?
Good question. I would assume the minimum height.
What are %ge inline/block sizes resolved against?
During the first pass, auto? During the second pass, which will be required anyway, I suspect we can resolve them, and just like we do with other cells, if there's an overflow, we let the content overflow.
Does that make sense to you?
vertical-align operates in the block-axis of the table cell
vertical-align: baseline is interesting. There is no "row baseline", what does baseline alignment means here?
I would assume it's simply being ignored in this case.
vertical-align: baseline is interesting. There is no "row baseline", what does baseline alignment means here?
On an orthogonal cell, it means the cell doesn't participate in baseline alignment across cells in the same row, but it could participate in alignment across cells in the same column. I don't know how awful that would be implementation-wise given the state of table algorithms, but it's how things are defined for grids IIRC. :)
On an orthogonal cell, it means the cell doesn't participate in baseline alignment across cells in the same row, but it could participate in alignment across cells in the same column.
I think that column baseline alignment for tables should not be supported unless someone demonstrates clear need for it. Implementing it is non-trivial, and has a corner case that cannot be implemented: descendants with percentage block sizes.
Baseline computation for rows algorithm: 1) in measuring phase, each row computes an intrinsic baseline. This baseline is used to compute row's height. Block percentages resolution size is 0. 2) Layout phase requires up to 2 passes. 3) Layout pass 1 is optional. If baseline aligned TDs have a descendant with percentage block size, an optional baseline resolution layout is needed to compute new baseline. Baseline is recomputed by doing layout where block percentage resolution size is row height. 4) Layout pass 2 is required. TDs are laid out, and their content vertically positioned based on vertical alignment.
What happens when all cells are orthogonal? Is row height defined by minimum or maximum inline size?
Good question. I would assume the minimum height.
Agree,
What are %ge inline/block sizes resolved against?
During the first pass, auto? During the second pass, which will be required anyway, I suspect we can resolve them, and just like we do with other cells, if there's an overflow, we let the content overflow.
Agree.
Great, I'll be adding this into the spec, then.
vertical-align
on things other than table cells behaves differently than on table cells. I am only talking about table cells here.Does "vertical" actually mean vertical, or does it mean block axis? if it means block axis, is that based on the writing mode of the table, or of the table cell?
I think it should be the block axis of the table cell (otherwise there is no way adjust alignment of the table cell content in that direction), but as far as I can tell, there's no spec that says that.