csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[css-box-4] margin-trim auto-margins needs more clarification wrt. fallback alignment.

Open bfgeek opened this issue 1 year ago • 3 comments

Consider:

<!DOCTYPE html>
<div style="display: flex; margin-trim: block; align-items: end; width: 100px; border: solid 2px; height: 100px;">
  <div style="background: lime; margin: auto;">hi</div>
  <div style="background: lime; margin: auto;">hi</div>
</div>

Presuming that auto margins are trimmed, should the alignment of the items be the start or the end?

https://drafts.csswg.org/css-box-4/#margin-trim

bfgeek avatar Dec 19 '24 19:12 bfgeek

A third possibility is that we don't trim auto margins.

Interested to hear what Web authors think would be intuitive. CC @kizu @mirisuzanne @LeaVerou @jensimmons @bramus @SebastianZ @bradkemper

fantasai avatar Dec 17 '25 21:12 fantasai

I would expect end alignment, since that's what you get when you remove the auto block margins. That's my immediate take, without considering why I would or would not want auto margins trimmed.

mirisuzanne avatar Dec 18 '25 16:12 mirisuzanne

Looking at this, my intuition lets me agree with @mirisuzanne. If we agree that auto margins are trimmed ‒ and I think that's reasonable, as it makes the behavior consistent with other values for margin ‒ the margins get trimmed on both sides of the block axis, so they should be end-aligned.

Extending the question: What if we have margin-trim: block-start instead? In that case, I'd say they should be at the start, as only the end margin gets trimmed, so the auto value pushes them to the block start.

Sebastian

SebastianZ avatar Dec 18 '25 20:12 SebastianZ