Re: [csswg-drafts] [css-view-transitions-1] Enforce ::view-transition to be fixed position (#8505)

Summarizing an offline discussion on this.

The `position` property on any element can have 2 side-effects:

* It determines whether the element is out of flow and what it's containing block is. Even though `::view-transition`'s ancestor in the DOM hierarchy is its originating element, a.k.a the `documentElement`, we want it to be positioned relative to the the [snapshot root](https://drafts.csswg.org/css-view-transitions-1/#snapshot-root-concept). So the [spec](https://drafts.csswg.org/css-view-transitions-1/#view-transition:~:text=Its%20containing%20block%20is%20the%20snapshot%20root.) states that its containing block is always the snapshot root.
There is no use-case where an author would want to change that. In fact it would be odd to change it since the transform computed for `::view-transition-group` elements is relative to the [snapshot root](https://drafts.csswg.org/css-view-transitions-1/#view-transition:~:text=A%20transform%20that%20would%20map%20element%E2%80%99s%20border%20box%20from%20the%20snapshot%20root%20origin%20to%20its%20current%20visual%20position.).

* It determines whether the element itself is a containing block for its descendants. The `position: fixed` rule in UA CSS on `::view-transition` makes it a containing block for all its `::view-transition-group` child pseudo-elements. 
   
   It's unclear what happens if the author changes `::view-transition` to `position: static`. My read of the explanation [here](https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block:~:text=If%20the%20position%20property%20is%20absolute%2C%20the%20containing%20block%20is%20formed%20by%20the%20edge%20of%20the%20padding%20box%20of%20the%20nearest%20ancestor%20element%20that%20has%20a%20position%20value%20other%20than%20static%20(fixed%2C%20absolute%2C%20relative%2C%20or%20sticky).) is that we'd walk up the ancestor chain until we find a positioned ancestor which will be the root element, so we'd end up with ICB instead of snapshot root. Which is again odd because the coordinate space based on which UA computes transforms for these is the snapshot root.

So there's 2 proposals here:

* `position: fixed` on view-transition pseudos means their containing block is established by the snapshot root. So for example if the author sets `position: fixed` on `::view-transition-old` then it will be positioned relative to the snapshot root instead.

* Enforce that `position: fixed` in UA CSS for `::view-transition` is `!important` so authors can't override it. There is no use-case for them to do it now anyway. The only containing block above `::view-transition` is the snapshot root. And if they want some child to be positioned relative to that, they can use `position: fixed` for it.
   This avoids the need for another special rule for how we select the containing block if authors set `position` to `static` for `::view-transition`.

-- 
GitHub Notification of comment by khushalsagar
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8505#issuecomment-1499620572 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 6 April 2023 20:57:40 UTC