Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[css-grid][css-align] How items with synthesized baseline affect the size of intrinsic tracks #1365
Comments
mrego
added css-align-3 css-grid-1
labels
May 12, 2017
fantasai
added the
Needs Feedback/Review
label
Jun 21, 2017
|
I'm thinking that, since this is a bad situation in any case (trying to baseline-align orthogonal flows), I'm okay with the result that we currently get from the spec (option 1). Option 2 looks at least as bad, and would involve some changes I'm not confident about, and option 3 goes against the entire reasoning for having synthesized baselines. The result isn't pretty, but it's both (a) rare, and (b) well-defined already, so I'm okay with it as it is. |
I'm ok with this decision. I didn't have any preference and current behavior is as good as any other option. The only issue worth discussing would be the fact that Baseline Alignment alters box's intrinsic size. If we end up removing that behavior, implementation would be considerably simpler. |
This was referenced Jun 27, 2017
fantasai
added the
Agenda+ F2F
label
Jul 5, 2017
|
The problem is that the cyan box is allowed to grow into the new space cleared out below it by aligning to the baseline of the pink box. If we can prevent that growth from happening, then the cyan's baseline will stay the same in both rounds, and the layout stabilizes in the second round. Suggestion, then: when we do self-baseline-alignment, we add pretend-margin to both sides of the boxes, so that all the aligned boxes have identical margin-box sizes. In this example, then, the first round would give the pink box 125px of top margin, and the cyan box 25px of bottom margin (so both have a margin-box height of 175px). Then, when we go into the second round, both boxes already exactly fit into the new 175px row height. The cyan box's synthesized baseline is still at 150px, so the pink box is already aligned with it, and layout is finished. The yellow box still overflows the grid container by 25px, but otherwise things fit together nicely. What this means is that, if there are larger items in the row, the cyan item will not resize to fit the row. And we haven't solved that there will be some overflow in this case even though it's theoretically not necessary. But at least its size should be stabilized across cycles. Thoughts? We're not sure at the moment whether this is only needed for self-alignment, or whether it would apply to the pretend-padding of content alignment too. ~TJ and fantasai |
mrego commentedMay 12, 2017
Let's try to explain an issue we're hitting while trying to implement baseline alignment on CSS Grid Layout.
The example is a bit complex, so let's go step by step:
Columns have a fixed size, so we don't need to care about them.
Regarding rows, on the first run of the grid track sizing algorithm, to calculate the size of the first row it checks the heights of the items inside:
As the 2nd row has 50px and the grid container has a fixed height of 200px, the 1st row ends up being 150px tall.
Until here everything seems pretty clear. Let's move to the funny part.
Now we calculate the baselines to apply the alignment to the items in the first row.
We take the biggest one 150px baseline and calculate the baseline offsets:
Here the min-content contribution of the first item has changed, before it was 50px, and now it's 175px = 125px (the baseline offset) + 50px (its height). So we've to do a new run of the algorithm.
In this second run to compute the size of the first row we do:
The first row has to be now 175px height, the 2nd row is fixed so it has 50px height and it overflows the container (not a big deal as that's what happens in similar cases without baseline alignment).
Problem comes now, what should we do at this point?
Option 1)
Following the approach above, we'd recompute the baselines offests:
The biggest baseline is 175px so we calculate the offsets again:
Then we'd stop, as the algorithm just ask to repeat it only once.
The result would be:
Option 2)
We avoid to recompute the baselines and reuse the biggest one from the previous run, which was 150px.
Then we calculate the new offsets:
Again, this is the 2nd run so we stop at this point.
The result would be:
Option 3)
As a last resort we could think on a different approach that would be to ignore the items with synthesized baseline. So in this case both items will be on the top of the first row and have a height of 50px and 150px (so the row would be 150px). But probably we don't want this.
What do you think?