Skip to content

Commit 5a1de32

Browse files
committed
fix: enhance documentation on view transition classes and pseudo-elements
1 parent f201a4a commit 5a1de32

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/content/docs/basics/pseudos.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ When it creates a `::view-transition-group-children` pseudo element, the View Tr
478478

479479
You define the nesting by setting the `view-transition-group` property on an element. The `view-transition-group` property only works on an element that also has a `view-transition-name`, as it determines how the new group is inserted into the tree of view transition groups. Special values for `view-transition-group` are `normal`, `nearest`, and `contain`. You can also use the name of another group as a value to declare the new group being a child of the referenced group.
480480

481+
The parent group of a new group pseudo element is determined when the group is first created. I.e. for groups that are defined in the old state, the styling of the new state won't affect the parent-child relationship of the groups. This holds for both, same-document and cross-document view transitions.
481482

482483
If you do not explicitly set the `view-transition-group` property of an element, it defaults to `normal`.
483484

src/content/docs/basics/styling.mdx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,27 +327,57 @@ If multiple class names are used to identify a pseudo element, all must match. T
327327
}
328328
```
329329

330-
Or shorter, without the star:
330+
331+
This is how you assign the classes
331332

332333
```css
333-
::view-transition-group(.nav-link) {
334-
/* ... */
334+
#navbar a {
335+
view-transition-class: nav-link; /* one class */
336+
}
337+
#prev,
338+
#next {
339+
view-transition-class: nav-link some-other-class; /* multiple classes, space separated */
335340
}
336341
```
337342

338-
This is an example on how to assign the class:
343+
This might best be combined with [dynamically added view transition names](/tips/auto-names/).
344+
345+
As in normal pseudo-element selectors without view transition classes, you can also use a view transition name instead of the star to address the pseudo element for that name.
339346

340347
```css
341-
#navbar a {
342-
view-transition-class: nav-link;
348+
::view-transition-group(card5.card) {
349+
/* ... */
343350
}
344-
#prev,
345-
#next {
346-
view-transition-class: nav-link some-other-class;
351+
```
352+
This will select the view transition group pseudo for the view transition name `card5`, but only if the element also has the `.card` view transition class.
353+
Like with CSS classes, you can even have multiple view transition classes one selector.
354+
355+
```css
356+
::view-transition-group(*.card.special) {
357+
/* ... */
358+
}
359+
```
360+
Make sure you have no whitespace in such a selector.
361+
362+
The above selector selects all groups that have both view transition classes:
363+
364+
```css
365+
view-transition-class: card; /* won't be selected, view transition class special is missing */
366+
view-transition-class: special; /* won't be selected, view transition class card is missing */
367+
view-transition-class: special card; /* will be selected, order does not matter */
368+
view-transition-class: card something special /* also fine, element might have additional classes */
369+
```
370+
371+
The view transition class names for a group and all its children are defined when the group is last encountered [during capturing](/basics/pseudos/#view-transition-names). A group that is present in the new state will have the class names defined in the new state styles. Only groups that were only present in the old state will have the view transition class names defined on the old state styling. This holds for both, same-document and cross-document view transitions.
372+
373+
Does that sound a bit complicated? Good news: the most common case is also the simplest: the `*` can be omitted in selectors that use view transition class names. With a single class, the card example from above then looks like this:
374+
375+
```css
376+
::view-transition-group(.nav-link) {
377+
/* ... */
347378
}
348379
```
349380

350-
This might best be combined with dynamically (per script) added view transition names or tooling where you declaratively assign view transition names.
351381

352382
### …with Types
353383

0 commit comments

Comments
 (0)