Skip to content

Commit 9f3602b

Browse files
committed
[css-scroll-snap] Refactor scroll-snap-align again, bringing the syntax to three significant changes from last week: 1. Adding percentages as an alignment possibility (representing between start and end); 2. Adding the 'point' keyword to distinguish 1D from 2D snapping; and 3. Assigning a single alignment value's axis by referencing 'overflow' (rather than assigning to both axes, which gives bad results in the fairly common case of author having only vertical overflow, and user having overflow in both axes)
1 parent aaa8860 commit 9f3602b

1 file changed

Lines changed: 56 additions & 36 deletions

File tree

css-scroll-snap/Overview.bs

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,15 @@ Scroll Snapping Alignment: the 'scroll-snap-align' property {#scroll-snap-align}
436436

437437
<pre class="propdef">
438438
Name: scroll-snap-align
439-
Value: [ x | y | block | inline ]? [ none | start | end | center | edges | <<percentage>> ]
440-
| point || xy? [ none | start | end | center | <<percentage>> ]{1,2}
439+
Value: [ none | edges | <alignment> ] {1,2} |
440+
[ block | inline] [ none | edges | <alignment> ] |
441+
point <alignment>{1,2}
441442
Initial: none
442443
Applies to: all elements
443444
Inherited: no
444-
Percentages: refer to size of scroller's <a>snap target area</a> <em>minus</em> size of box's <a>snap area</a>
445-
Computed value: as specified
445+
Percentages: refer to size of scroll container's <a>snap target area</a> <em>minus</em> size of box's <a>snap area</a>
446+
Computed value: an optional ''point'' keyword, plus one or two alignment values
447+
each consisting of either a ''none'' or ''edges'' keyword or a percentage
446448
Animatable: no
447449
Media: interactive
448450
</pre>
@@ -454,18 +456,30 @@ Scroll Snapping Alignment: the 'scroll-snap-align' property {#scroll-snap-align}
454456
or as a simultaneous 2D alignment position,
455457
by using a <a>scroll axis keyword</a>.
456458

459+
<pre class="prod">
460+
<dfn for=scroll-snap-align><<alignment>></dfn> = center | [ start | end ] <percentage>?
461+
</pre>
462+
463+
Issue: This is a subset of the L4 <<position> syntax
464+
that works within the constraint of an axis.
465+
It also aligns with the <<self-position>> syntax from [[CSS-ALIGN-3]] (see e.g. 'align-self').
466+
We could simplify to ''center | start | end'' by dropping <<percentage>>
467+
(which would be a true subset of <<self-position>>),
468+
or expand to a full logical/physical combination syntax
469+
(as a fuller, and therefore more complicated, subset of <<position>>).
470+
457471
<div class="example">
458-
The following example aligns the block-start edge of the box's <a>snap area</a>
459-
to the block-start edge of the scroller's <a>snap target area</a>:
472+
The following example aligns the start edge of the box's <a>snap area</a>
473+
to the start edge of the scroll container's <a>snap target area</a>:
460474
<pre>section { scroll-snap-align: start; }</pre>
461475

462476
The following example aligns the center of each city
463-
to the center of the scroller's <a>snap target area</a>,
477+
to the center of the scroll container's <a>snap target area</a>,
464478
snapping only when the city is centered in both axes:
465479
<pre>city { scroll-snap-align: center point; }</pre>
466480

467481
The following example aligns the center of each photo
468-
to the center of the scroller's <a>snap target area</a>,
482+
to the center of the scroll container's <a>snap target area</a>,
469483
snapping independently in each axis:
470484
<pre>img { scroll-snap-align: center; }</pre>
471485
</div>
@@ -480,72 +494,78 @@ Scroll Snapping Alignment: the 'scroll-snap-align' property {#scroll-snap-align}
480494
<dt><dfn>start</dfn>
481495
<dd>
482496
Start alignment of this box's <a>scroll snap area</a>
483-
within the scroller's <a>scroll snap target area</a>
497+
within the <a>scroll container</a>'s <a>scroll snap target area</a>
484498
is a valid <a>snap position</a>.
485-
Equivalent to ''0%''.
486499

487500
<dt><dfn>end</dfn>
488501
<dd>
489502
End alignment of this box's <a>scroll snap area</a>
490-
within the scroller's <a>scroll snap target area</a>
503+
within the <a>scroll container</a>'s <a>scroll snap target area</a>
491504
is a valid <a>snap position</a>.
492-
Equivalent to ''100%''.
493505

494506
<dt><dfn>center</dfn>
495507
<dd>
496508
Center alignment of this box's <a>scroll snap area</a>
497-
within the scroller's <a>scroll snap target area</a>
509+
within the <a>scroll container</a>'s <a>scroll snap target area</a>
498510
is a valid <a>snap position</a>.
499-
Equivalent to ''50%''.
500511

501512
<dt><dfn><<percentage>></dfn>
502513
<dd>
503514
Percentage alignment of this box's <a>scroll snap area</a>
504-
within the scroller's <a>scroll snap target area</a>
515+
within the <a>scroll container</a>'s <a>scroll snap target area</a>
505516
is a valid <a>snap position</a>,
506517
where the percentage represents a position between
507-
''scroll-snap-align/start'' alignment (''0%'') and ''scroll-snap-align/end'' alignment (''100%'').
518+
''scroll-snap-align/start'' alignment and ''scroll-snap-align/end'' alignment.
519+
''0%'' matches the given alignment keyword (''scroll-snap-align/start'' or ''scroll-snap-align/end'').
508520

509521
<dt><dfn>edges</dfn>
510522
<dd>
511523
Both start alignment and end alignment of this box's <a>scroll snap area</a>
512-
within the scroller's <a>scroll snap target area</a>
513-
is a valid <a>snap position</a>.
514-
Equivalent to ''50%''.
524+
within the <a>scroll container</a>'s <a>scroll snap target area</a>
525+
are valid <a>snap positions</a>.
515526
</dl>
516527

517-
If no <a>scroll axis keyword</a> is specified, then
518-
a single <a>scroll alignment value</a> specifies alignment in the block axis only;
519-
if two values are specified, then
520-
the first value specifies alignment in the inline axis;
521-
and the second value (if any) specifies alignment in the block axis.
522-
<span class="issue">Is the correct default assignment?</span>
523-
524528
The <dfn>scroll axis keywords</dfn>
525-
allow targeting a specific axis
529+
allow explicitly targeting a specific axis
526530
or requesting simultaneous 2D alignment,
527531
and are defined as follows:
528532

529533
<dl dfn-type=value dfn-for=scroll-snap-align>
530-
<dt><dfn>x</dfn>
531-
<dt><dfn>y</dfn>
532-
<dd>
533-
The specified alignment applies to the x (horizontal) or y (vertical) axis, respectively.
534534
<dt><dfn>inline</dfn>
535535
<dt><dfn>block</dfn>
536536
<dd>
537537
The specified alignment applies to the inline or block axis, respectively.
538-
<dt><dfn>xy</dfn>
539-
<dd>
540-
The specified 2-value alignment applies to the x and y axes
541-
(rather than to the block and inline axes).
538+
The computed alignment of the opposite axis is set to ''scroll-snap-align/none''.
539+
540+
<div class="example">
541+
The following two declarations are equivalent:
542+
<pre>
543+
scroll-snap-align: none start;
544+
scroll-snap-align: block start;
545+
</pre>
546+
</div>
547+
542548
<dt><dfn>point</dfn>
543549
<dd>
544-
The <a>snap position</a> is only valid when both axes are aligned as specified;
550+
Specifies 2D snapping:
551+
the <a>snap position</a> is only valid when both axes are aligned as specified;
545552
otherwise the <a>snap position</a> in each axis
546553
is independent of alignment in the other axis.
547554
</dl>
548555

556+
If two <<alignment>> values are specified, then
557+
the first value specifies alignment in the inline axis;
558+
and the second value (if any) specifies alignment in the block axis.
559+
560+
If only one value is specified
561+
and no <a>scroll axis keyword</a> is specified, then
562+
the <<alignment>> value
563+
applies to the scrollable axis of the affected <a>scroll container</a>.
564+
If both axes are scrollable
565+
(i.e. both 'overflow-x' and 'overflow-y' are either ''overflow/scroll'' or ''overflow/auto''),
566+
then it applies to the block axis of the affected <a>scroll container</a>
567+
(as determined by the <a>scroll container</a>’s <a>writing mode</a>).
568+
549569
Note: Remember that in <a>vertical writing modes</a> the block and inline axes
550570
correspond to the x and y axes, and not the y and x axes, respectively.
551571

0 commit comments

Comments
 (0)