diff --git a/src/content/docs/basics/pseudos.mdx b/src/content/docs/basics/pseudos.mdx index 6559f2e..679bad2 100644 --- a/src/content/docs/basics/pseudos.mdx +++ b/src/content/docs/basics/pseudos.mdx @@ -185,7 +185,7 @@ This default defines an animation for the current viewport. If you want to anima ``` The special value `none` removes a potentially set view transition name. -Other special names are [`match-element`](#auto-generated-names-match-element) and `auto`, and all names beginning with `-ua-`. +Other special names are [`match-element`](#auto-generated-names-match-element) and [`auto`](#auto-generated-names-auto), and all names beginning with `-ua-`. ### Escaping Do not quote the names. They are not strings but [custom-ident](https://developer.mozilla.org/de/docs/Web/CSS/custom-ident) values. Ensure proper escaping of special characters. The simplest, most portable approach is to just use upper and lower case letters from A to Z, digits from 0 to 9, an underscore `_` or a hyphen `-` character. But don't start the name with a digit. While all other characters with a code < 128 need to be escaped, codes > 127 like 😄 seem to work just fine in view transition names. In browsers, you can use `CSS.escape()` to properly escape strings as custom identifiers. @@ -207,7 +207,7 @@ However, it is also possible to do this with only CSS by using the `match-elemen Using `match-element` assigns a generated name that is bound to the DOM element. Those names typically look like `-ua-....` with some random suffix. Two different elements are always assigned different values. -When you set the view transition name multiple times for the same element that way, it will always get the same name. + How could you style your pseudo-elements, if they have an unknown random name? The general approach here is to also assign a view transition class. ```css @@ -219,10 +219,10 @@ How could you style your pseudo-elements, if they have an unknown random name? T The class name does not need to be unique across elements. Then [use the view transition class name](/basics/styling/#with-classes) in your style rules. This works fine for **same-document** view transitions on supporting browsers. -For **cross-document** view transitions, generated names for the two document should never be the same. Therefore groups created from `match-element` in cross-document view transitions wi ll always have image-pairs with a single old or new image, only. +For **cross-document** view transitions, generated names for the two document should never be the same. Therefore groups created from `match-element` in cross-document view transitions will always have image-pairs with a single old or new image, only. :::caution -That is, if they are created. Safari seems to handle `match-element` like `none` in cross-document view transitions for elements that do not define an `id`. +Safari seems to handle `match-element` like `none` in cross-document view transitions, i.e. it does not generate any names when view transitions are enabled via `@view-transition{navigate-auto}`. It does generate names when the transition ist started by calling `startViewTransition()`. ::: Until it gets broader, convergent support in browsers, **I would not recommend `match-element`** for cross-document view transitions. There are [alternatives](/tips/auto-names/#how-to-assign-names-automatically) that work cross-browser and also for cross-document navigation. @@ -238,20 +238,22 @@ selector { view-transition-name: auto; } ``` -This is similar to `match-element` but it also takes the `id` property of an HTML element into account: If the `id` property is set, `auto` generates the same view transition name for all elements with that `id`, independent of the document that element belongs to. -Different ids generate different view transition names. The generated name has to start with `-ua-`. +This is similar to `match-element` but it also takes the `id` property of an HTML element into account: If the `id` property is set, `auto` generates the same view transition name for all elements with that `id`, independent of the document that element belongs to. +Different ids generate different view transition names. + +So the main use case here is to match elements with the same id in cross-document view transitions. But it also works with `startViewTransition`. Just make sure that your `id` values are unique as it should be even if not enforced by browsers. Otherwise you might get duplicate view transition names and the view transition gets skipped with an error. Different browsers and browser versions show divergent behavior. Safari uses the `id` value as view transition name. On some Webkit versions you might also see `-ua-id-`, where `` is the element's `id` value. Chrome uses random values similar to those generated for `match-element`. :::caution -Like with `match-element`, Safari seem to not generate random names for cross-document view transitions enabled with `@view-transition{navigation: auto}`. Only for view transitions started by `startViewTransition()`. +As with `match-element`, if `id` is not set, Safari does not seem to generate random names for cross-document view transitions. It does so for same-document view transitions. ::: ### Using id as View Transition Name _Not available across browsers, yet._ -On Chromium browsers you would use the following incantation to use the id attribute as an view transition name: +On recent Chromium browsers you could use the following incantation to re-use the `id` attribute as an view transition name: ```css view-transition-name: attr(id type(), none); ```