-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.bs
More file actions
executable file
·1783 lines (1578 loc) · 63.7 KB
/
Overview.bs
File metadata and controls
executable file
·1783 lines (1578 loc) · 63.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: Motion Path Module Level 1
Shortname: motion
Level: 1
Status: ED
Prepare for TR: no
Issue Tracking: GitHub https://github.com/w3c/fxtf-drafts/labels/motion-1
Work Status: Refining
ED: https://drafts.csswg.org/motion-1/
TR: https://www.w3.org/TR/motion-1/
Group: csswg
Editor: Dirk Schulze, Adobe Inc., dschulze@adobe.com, w3cid 51803
Editor: Jihye Hong, Igalia, jihye@igalia.com, w3cid 79168
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/, w3cid 42199
Former Editor: Shane Stephens, Google, shanestephens@google.com, w3cid 47691
Former Editor: Eric Willigers, then Google, ericwilligers@google.com, w3cid 67534
Test Suite: https://github.com/web-platform-tests/wpt/tree/master/css/motion
Abstract: Motion path allows authors to position any graphical object and animate it along an author specified path.
WPT Path Prefix: css/motion/
WPT Display: closed
</pre>
<pre class=link-defaults>
spec:css-transforms-1; type:dfn;
text:local coordinate system
spec:svg2; type:dfn;
text: segment-completing close path
spec: css-backgrounds-3; type:property;
text: border-radius
spec:motion-1; type:value;
text:path()
spec:css-shapes-1; type:dfn;
text:shape()
</pre>
Introduction {#intro}
=====================
<em>This section is not normative.</em>
The 'transform' property and its related properties
allow a [=box=] to be arbitrarily repositioned
(and rotated, scaled, etc)
relative to its laid out position,
without disrupting the layout of any other elements on the page.
These positions can be animated or transitioned with CSS,
but only in relatively simple ways:
moving a box in a straight line from its starting position to its ending position.
This specification introduces the 'offset' shorthand,
and its suite of associated longhand properties,
which define an <dfn export>offset transform</dfn>:
a transform which aligns a particular point on an element
('offset-anchor')
to an <dfn export>offset position</dfn> on a <em>path</em>
('offset-path' and 'offset-distance'),
and optionally rotates it to follow the path direction
('offset-rotate').
This allows a number of powerful new transform possibilities,
such as positioning using polar coordinates
(with the ''ray()'' function)
rather than the standard rectangular coordinates
used by the ''translate()'' function,
or animating an element <em>along a defined path</em>,
making it easy to define complex and beautiful 2d spatial transitions.
<div class=example>
For example,
the following picture shows a curving path
(indicated with dotted lines),
and an airplane graphic positioned
at various points along the path.
The plane faces in the direction of the path at each position on the path.
<figure>
<img src="images/motion-path.svg" width="470" height="120" alt="Example Path">
<p class=caption>The plane is shown at different 'offset-distance' values: ''0%'', ''50%'', and ''100%''.</p>
</figure>
</div>
Module interactions {#placement}
--------------------------------
This specification defines additional types of transforms
(see [[css-transforms-1]])
that can be applied to an element.
As described in [[css-transforms-2#ctm]],
the transforms defined by this document are layered
after the individual transform properties
('translate'/'rotate'/'scale', defined in [[css-transforms-2]])
and before the 'transform' property
(defined in [[css-transforms-1]]).
Values {#values}
----------------
This specification follows the <a href="https://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]].
The <<basic-shape>> type is defined in CSS Shapes Module Level 1 [[!CSS-SHAPES]].
The <<coord-box>> type is defined in CSS Box Model Module Level 3 [[!CSS-BOX-3]].
Value types not defined in these specifications are defined in CSS Values and Units Module Level 3 [[!CSS3VAL]].
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept CSS-wide keywords such as <a href="https://drafts.csswg.org/css-cascade-4/#valdef-all-initial">initial</a> and <a href="https://drafts.csswg.org/css-cascade-4/#valdef-all-inherit">inherit</a> as their property value [[!CSS3VAL]]. For readability it has not been repeated explicitly.
Motion Paths {#motion-paths-overview}
=====================================
<!--
████████ ███ ████████ ██ ██
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
███████ ████████ ██ ██ ██ █████████
██ █████████ ██ ██ ██
██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██
-->
Defining A Path: the 'offset-path' property {#offset-path-property}
-----------------------------------------------------------------
<pre class=propdef>
Name: offset-path
Value: none | <<offset-path>> || <<coord-box>>
Initial: none
Applies to: [=transformable elements=]
Inherited: no
Percentages: n/a
Computed value: as specified
Media: visual
Animation type: by computed value
</pre>
Specifies the <dfn export>offset path</dfn>,
a geometrical path the box gets positioned on.
<pre class=prod>
<dfn><offset-path></dfn> = <<ray()>> | <<url>> | <<basic-shape>>
</pre>
Values have the following meanings:
<dl dfn-for=offset-path dfn-type=value>
: <dfn>none</dfn>
:: The element does not have an [=offset transform=].
: <dfn><<offset-path>> || <<coord-box>></dfn>
::
The element has an [=offset transform=],
defined by some [=offset path=].
See [[#transform]] for details
on how to calculate the [=offset transform=].
All the usual effects of having a 'transform' apply
(such as creating a [=stacking context=], etc.)
See [[css-transforms-1#transform-rendering]] for details.
If <<offset-path>> is omitted,
it defaults to <css>inset(0 round <var>X</var>)</css>,
where <var>X</var> is the value of 'border-radius'
on the element that establishes the [=containing block=]
for this element.
If <<coord-box>> is omitted,
it defaults to ''<coord-box>/border-box''.
See the specific values (below)
for the interpretation of each component.
: <dfn><<ray()>></dfn>
::
The [=offset path=] is a line
extending from the [=ray()/origin=]
at some angle.
See [[#ray-function]] for details.
The <<coord-box>> provides the [=<basic-shape>/reference box=]
for the ray.
: <dfn><<url>></dfn>
::
A URL reference to an SVG [=shape element=].
The [=offset path=] is the referenced element's <l spec=svg2>[=equivalent path=]</l>.
[[!SVG2]]
If the URL does not reference a [=shape element=]
(because it references a different element,
or resolves to a non-SVG document,
or doesn't resolve at all,
etc)
this behaves as ''path("m 0 0")''
(a <<basic-shape>>)
instead.
The <<coord-box>> defines the viewport and user coordinate system
for the [=shape element=],
with the origin (the 0,0 point) at the top left corner,
and units being ''1px'' in size.
: <dfn><<basic-shape>></dfn>
::
The [=offset path=] is the [=<basic-shape>/equivalent path=]
of the <<basic-shape>> function.
For all <<basic-shape>>s,
if they accept an ''at <<position>>'' argument
but that argument is omitted,
and the element defines an [=offset starting position=]
via 'offset-position',
it uses the specified [=offset starting position=]
for that argument.
Otherwise it defaults as specified for each function.
The <<coord-box>> provides the [=<basic-shape>/reference box=]
for the <<basic-shape>>.
: <dfn><<coord-box>></dfn>
::
Defines the box that the <<offset-path>> sizes into.
In CSS contexts,
the boxes being referenced
are from the element that establishes the [=containing block=]
for this element.
In SVG contexts,
all values behave as ''<coord-box>/view-box''.
</dl>
<wpt>
animation/offset-path-composition.html
animation/offset-path-coord-box-interpolation.html
animation/offset-path-interpolation-001.html
animation/offset-path-interpolation-002.html
animation/offset-path-interpolation-003.html
animation/offset-path-interpolation-004.html
animation/offset-path-interpolation-005.html
animation/offset-path-interpolation-006.html
animation/offset-path-interpolation-007.html
animation/offset-path-interpolation-008.html
animation/reftests/offset-path-path-interpolation-001.html
animation/reftests/offset-path-with-transforms-001.html
change-offset-path.html
offset-path-coord-box-001.html
offset-path-coord-box-002.html
offset-path-coord-box-003.html
offset-path-coord-box-004.html
offset-path-huge-angle-deg-001-crash.html
offset-path-huge-angle-grad-001-crash.html
offset-path-huge-angle-turn-001-crash.html
offset-path-ray-001.html
offset-path-ray-002.html
offset-path-ray-003.html
offset-path-ray-004.html
offset-path-ray-005.html
offset-path-ray-006.html
offset-path-ray-007.html
offset-path-ray-008.html
offset-path-ray-009.html
offset-path-ray-010.html
offset-path-ray-011.html
offset-path-ray-012.html
offset-path-ray-013.html
offset-path-ray-014.html
offset-path-ray-015.html
offset-path-ray-016.html
offset-path-ray-017.html
offset-path-ray-018.html
offset-path-ray-019.html
offset-path-ray-020.html
offset-path-ray-021.html
offset-path-ray-022.html
offset-path-ray-contain-001.html
offset-path-ray-contain-002.html
offset-path-ray-contain-003.html
offset-path-ray-contain-004.html
offset-path-ray-contain-005.html
offset-path-shape-circle-001.html
offset-path-shape-circle-002.html
offset-path-shape-circle-003.html
offset-path-shape-circle-004.html
offset-path-shape-circle-005.html
offset-path-shape-circle-006.html
offset-path-shape-circle-007.html
offset-path-shape-circle-008.html
offset-path-shape-ellipse-001.html
offset-path-shape-ellipse-002.html
offset-path-shape-ellipse-003.html
offset-path-shape-ellipse-004.html
offset-path-shape-ellipse-005.html
offset-path-shape-ellipse-006.html
offset-path-shape-ellipse-007.html
offset-path-shape-inset-001.html
offset-path-shape-inset-002.html
offset-path-shape-polygon-001.html
offset-path-shape-polygon-002.html
offset-path-shape-polygon-003.html
offset-path-shape-rect-001.html
offset-path-shape-rect-002.html
offset-path-shape-rect-003.html
offset-path-shape-shape-001.html
offset-path-shape-shape-002.html
offset-path-shape-shape-003.html
offset-path-shape-xywh-001.html
offset-path-shape-xywh-002.html
offset-path-shape-xywh-003.html
offset-path-string-001.html
offset-path-string-002.html
offset-path-string-003.html
offset-path-url-001.html
offset-path-url-002.html
offset-path-url-003.html
offset-path-url-004.html
offset-path-url-005.html
offset-path-url-006.html
offset-path-url-007.html
offset-path-url-008.html
offset-path-url-009.html
offset-path-url-010.html
offset-path-url-011.html
offset-path-url-crash.html
parsing/offset-path-computed.html
parsing/offset-path-parsing-invalid.html
parsing/offset-path-parsing-valid.html
parsing/offset-path-shape-computed.html
parsing/offset-path-shape-parsing.html
</wpt>
<!--
████████ ███ ██ ██ ███ ███
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ████ ██ ██
████████ ██ ██ ██ ██ ██
██ ██ █████████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ███ ███
-->
<h4 id=ray-function>
The ''ray()'' Function</h4>
The ''ray()'' function defines an [=offset path=]
as a straight line emerging from a point at some defined angle:
<pre class=prod>
<dfn>ray()</dfn> = ray( <<angle>> && <<ray-size>>? && contain? && [at <<position>>]? )
<dfn><ray-size></dfn> = <<radial-extent>> | sides
</pre>
Its arguments are:
<dl dfn-type=value dfn-for="ray()">
: <dfn><<angle>></dfn>
::
The <a>offset path</a> is a single line segment
that starts from the [=offset starting position=]
and proceeds in the direction defined by the specified <<angle>>.
(Its length is determined by the other arguments.)
As with [=gradient functions=],
<<angle>> values are interpreted as bearing angles,
with ''0deg'' pointing up
and positive angles representing clockwise rotation.
: <dfn><ray-size></dfn>
::
Specifies the length of the [=offset path=]
(the distance between the ''offset-distance: 0%''
and ''offset-distance: 100%'' points)
relative to the containing box.
If no <<ray-size>> is specified it defaults to ''closest-side''.
Note: For ''sides'',
the distance depends on the <<angle>> specified;
for all other values,
the distance is constant regardless of the <<angle>>.
Individual keywords are:
<dl dfn-for="<ray-size>">
: <dfn id=size-closest-side>closest-side</dfn>
:: The distance from the ray's starting point
to whichever side of the [=containing block=]
is closest.
: <dfn id=size-closest-corner>closest-corner</dfn>
:: The distance from the ray's starting point
to whichever corner of the [=containing block=]
is closest.
: <dfn id=size-farthest-side>farthest-side</dfn>
:: The distance from the ray's starting point
to whichever side of the [=containing block=]
is farthest.
: <dfn id=size-farthest-corner>farthest-corner</dfn>
:: The distance from the ray's starting point
to whichever corner of the [=containing block=]
is farthest.
: <dfn id=size-sides>sides</dfn>
:: The distance from the ray's starting point
to the point where the [=offset path=]
intersects the [=containing block's=] boundary.
If the ray's starting point
is on the [=containing block's=] boundary,
or outside its bounds entirely,
the distance is zero.
</dl>
Note: For ''closest-side'' and ''closest-corner'',
if the ray's starting point is <em>on</em> an edge/corner,
that's the closest one.
(In other words, the distance is zero.)
Note: For ''closest-side'' and ''farthest-side'',
if the ray's starting point is outside the [=containing block=] entirely,
the edges of the [=containing block=]
are considered to extend out to infinity.
: <dfn>contain</dfn>
::
The length of the [=offset path=] is reduced
so that the element stays within the [=containing block=]
even at ''offset-distance: 100%''.
Specifically, the path's length is reduced
by half the width or half the height of the element's border box,
whichever is larger,
and floored at zero.
<div class=note>
This behavior is optimized for a particular case--
the element's width and height are equal or nearly so;
the element is either completely rounded by 'border-radius'
or the corners aren't relevant to its appearance;
the ''ray()'' uses ''closest-side'' positioning;
and 'offset-anchor' is set to ''offset-anchor/center''.
Under these conditions,
which are common for situations
like positioning elements around the edge of a round clock face,
this ensures that each element is positioned
fairly snugly against the inner edge of the clock face
at ''offset-distance: 100%''.
In other conditions this will act <em>similarly</em>
but might not give quite as optimal a result.
</div>
: <dfn>at <<position>></dfn>
::
Specifies the <dfn dfn>origin</dfn> of the ray,
where the ray's line begins
(the 0% position).
It's resolved by using the <<position>>
to position a 0x0 object area
within the box's [=containing block=].
If omitted, it uses the [=offset starting position=]
of the element,
given by 'offset-position'.
If the element doesn't have an [=offset starting position=] either,
it behaves as ''at center''.
Note: ''ray()'' is currently only usable as an [=offset path=].
If it ever gets extended to other uses,
its usage of 'offset-position'
will be limited solely to when it's an [=offset path=],
similar to other <<basic-shape>> functions.
</dl>
<wpt>
animation/ray-angle-interpolation-math-functions.html
offset-path-ray-001.html
offset-path-ray-002.html
offset-path-ray-003.html
offset-path-ray-004.html
offset-path-ray-005.html
offset-path-ray-006.html
offset-path-ray-007.html
offset-path-ray-008.html
offset-path-ray-009.html
offset-path-ray-010.html
offset-path-ray-011.html
offset-path-ray-012.html
offset-path-ray-013.html
offset-path-ray-014.html
offset-path-ray-015.html
offset-path-ray-016.html
offset-path-ray-017.html
offset-path-ray-018.html
offset-path-ray-019.html
offset-path-ray-020.html
offset-path-ray-021.html
offset-path-ray-022.html
offset-path-ray-contain-001.html
offset-path-ray-contain-002.html
offset-path-ray-contain-003.html
offset-path-ray-contain-004.html
offset-path-ray-contain-005.html
</wpt>
Issue: all of these examples need to be rewritten.
<div class=example>
Here are some examples. The first example shows that some parts of boxes are outside of the <a>offset path</a>.
<pre><code highlight=html>
<style>
body {
transform-style: preserve-3d;
width: 200px;
height: 200px;
}
.box {
width: 50px;
height: 50px;
offset-position: 50% 50%;
offset-distance: 100%;
offset-rotate: 0deg;
}
#redBox {
background-color: red;
offset-path: ray(45deg closest-side);
}
#blueBox {
background-color: blue;
offset-path: ray(180deg closest-side);
}
</style>
<body>
<div class="box" id="redBox"></div>
<div class="box" id="blueBox"></div>
</body>
</code></pre>
<figure>
<img alt="An image of boxes positioned without contain" src="images/offset_distance_without_contain.png" width="200" height="220">
<figcaption>'offset-path' without 'contain'</figcaption>
</figure>
In the second example, 'contain' is given to the 'offset-path' value of each box
to avoid overflowing.
<pre><code highlight=html>
<style>
body {
transform-style: preserve-3d;
width: 200px;
height: 200px;
}
.box {
width: 50px;
height: 50px;
offset-position: 50% 50%;
offset-distance: 100%;
offset-rotate: 0deg;
}
#redBox {
background-color: red;
offset-path: ray(45deg closest-side contain);
}
#blueBox {
background-color: blue;
offset-path: ray(180deg closest-side contain);
}
</style>
<body>
<div class="box" id="redBox"></div>
<div class="box" id="blueBox"></div>
</body>
</code></pre>
<figure>
<img alt="An image of boxes positioned with contain" src="images/offset_distance_with_contain.png" width="200" height="220">
<figcaption>'offset-path' with 'contain'</figcaption>
</figure>
In the third example, the path size is increased so that the box can be contained. The <a>used offset distance</a> is negative.
<pre><code highlight=html>
<style>
body {
transform-style: preserve-3d;
width: 250px;
height: 250px;
}
.box {
width: 60%;
height: 10%;
offset-position: 20% 20%;
offset-distance: 0%;
offset-rotate: 0deg;
offset-anchor: 200% -300%;
}
#blueBox {
background-color: blue;
offset-path: ray(-90deg closest-side contain);
}
</style>
<body>
<div class="box" id="blueBox"></div>
</body>
</code></pre>
<figure>
<img alt="An image of an increased path size" src="images/increase-size.svg" width="400" height="335">
<figcaption>'offset-path' with path size increased</figcaption>
</figure>
In the fourth example, the initial position is outside the containing block.
<pre><code highlight=html>
<style>
#container {
transform-style: preserve-3d;
width: 200px;
height: 200px;
}
.box {
width: 20%;
height: 20%;
offset-position: 140% 70%;
offset-distance: 100%;
}
#redBox {
background-color: red;
offset-path: ray(-90deg sides);
}
#blueBox {
background-color: blue;
offset-path: ray(180deg closest-side);
}
</style>
<div id="container">
<div class="box" id="redBox"></div>
<div class="box" id="blueBox"></div>
</div>
</code></pre>
<figure>
<img alt="An image with initial position outside the containing block" src="images/initial-outside.svg" width="700" height="460">
<figcaption>Initial position outside the containing block</figcaption>
</figure>
</div>
### Examples Of <<basic-shape>> Positioning ### {#example-shape}
<div class=example>
This example uses a circle with implicit center position.
<pre><code highlight=html>
<style>
body {
width: 323px;
height: 131px;
margin: 0px;
border: 2px solid black;
padding: 8px;
transform-style: preserve-3d;
}
.item {
width: 90px;
height: 40px;
background-color: violet;
}
#middle {
offset-position: auto;
offset-path: circle(60%) margin-box;
offset-distance: 25%;
offset-anchor: left top;
}
</style>
<body>
<div class="item"></div>
<div class="item" id="middle"></div>
<div class="item"></div>
</body>
</code></pre>
<figure>
<img src="images/normal-flow.svg" width="505" height="324" alt="Normal flow determining circle center">
<figcaption>The circle center is determined by normal flow.</figcaption>
</figure>
</div>
### Examples of <<coord-box>> Positioning ### {#example-coord}
<div class=example>
This example shows how <<coord-box>> <a>offset path</a> works in combination with 'border-radius'.
<pre><code highlight=html>
<style>
body {
width: 500px;
height: 300px;
border-radius: 80px;
border: dashed aqua;
margin: 0;
}
#blueBox {
width: 40px;
height: 20px;
background-color: blue;
offset-path: margin-box;
}
</style>
<body>
<div id="blueBox"></div>
</body>
</code></pre>
<figure>
<img alt="An image of example for geometry-box with border-radius" src="images/geometry-box.svg" width="470" height="270">
<figcaption>The initial position is the left end of the top horizontal line.</figcaption>
</figure>
</div>
<!--
████████ ████ ██████ ████████ ███ ██ ██ ██████ ████████
██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
███████ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██████
██ ██ ██ ██ ██ █████████ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
████████ ████ ██████ ██ ██ ██ ██ ██ ██████ ████████
-->
Position On The Path: the 'offset-distance' property {#offset-distance-property}
--------------------------------------------------------------------------------
<pre class=propdef>
Name: offset-distance
Value: <<length-percentage>>
Initial: 0
Applies to: [=transformable elements=]
Inherited: no
Percentages: relative to the [=offset path=] length
Computed value: a computed <<length-percentage>> value
Media: visual
Animation type: by computed value
</pre>
Specifies where along the [=offset path=]
the [=offset position=] is.
<dl dfn-for="offset-distance" dfn-type="value">
: <<length-percentage>>
::
The [=offset position=] is the point
that is the specified distance
along the element's [=offset path=].
See [[#path-distance]] for details
about how to calculate distances along a path.
Percentages are relative to the total length of the [=offset path=].
</dl>
<wpt>
animation/offset-distance-composition.html
animation/offset-distance-interpolation.html
animation/reftests/offset-distance-interpolation-001.html
offset-distance-001.html
offset-distance-002.html
offset-distance-003.html
offset-distance-004.html
offset-distance-005.html
offset-distance-006.html
offset-distance-007.html
offset-distance-008.html
offset-distance-009.html
parsing/offset-distance-computed.html
parsing/offset-distance-parsing-invalid.html
parsing/offset-distance-parsing-valid.html
</wpt>
Note: By animating the 'offset-distance',
an element can easily trace out a complex path.
If the element does not have an [=offset path=],
this property does nothing.
### Calculating the computed distance along a path ### {#path-distance}
Processing the distance along an <a>offset path</a> operates differently depending upon the nature of the <a>offset path</a>:
* References to <<angle>> <a>offset path</a>s with contain are unclosed intervals.
* References to <<angle>> <a>offset path</a>s without contain are unbounded rays.
* All basic CSS shapes are closed loops.
* <a>Offset path</a>s (including references to SVG Paths) are closed loops only if the final command in the path list is a closepath command ("z" or "Z"), otherwise they are unclosed intervals.
* References to SVG circles, ellipses, images, polygons and rects are closed loops.
* References to SVG lines and polylines are unclosed intervals.
To determine the <dfn>used offset distance</dfn> for a given <a>offset path</a> and <dfn>offset distance</dfn>:
1. Let the <dfn>total length</dfn> be the total length of <a>offset path</a> with all sub-paths.
2. Convert <a>offset distance</a> to pixels, with 100% being converted to <a>total length</a>.
3. <dl class=switch>
: If <a>offset path</a> is an unbounded ray:
:: Let <a>used offset distance</a> be equal to <a>offset distance</a>.
: Otherwise if <a>offset path</a> is an <<angle>> path with contain:
:: Let <a>used offset distance</a> be equal to <a>offset distance</a>, clamped so that the box lies entirely within the path.
: If <a>offset path</a> is any other unclosed interval:
:: Let <a>used offset distance</a> be equal to <a>offset distance</a> clamped by 0 and the total length of the path.
: Otherwise <a>offset path</a> is a closed loop:
:: Let <a>used offset distance</a> be equal to <a>offset distance</a> modulo the total length of the path. If the total length of the path is 0, <a>used offset distance</a> is also 0.
Note: “Modulo” here uses the traditional mathematical definition,
where the output is always non-negative.
</dl>
<div class=example>
This example shows boxes placed along an unclosed interval.
<pre><code highlight=html>
<style>
.item {
width: 100px;
height: 40px;
offset-position: 0% 0%;
offset-path: path('m 0 0 h 200 v 150');
}
#box1 {
background-color: red;
offset-distance: -280%;
}
#box2 {
background-color: green;
offset-distance: 190%;
}
</style>
<body>
<div class="item" id="box1"></div>
<div class="item" id="box2"></div>
</body>
</code></pre>
<figure>
<img src="images/offset-distance-unclosed.svg" width="700" height="270"
alt="An example of boxes placed along an unclosed interval">
<figcaption>An example of boxes placed along an unclosed interval</figcaption>
</figure>
</div>
<div class=example>
This example shows boxes placed along a closed interval.
<pre><code highlight=html>
<style>
.item {
width: 100px;
height: 40px;
offset-position: 0% 0%;
offset-path: path('m 0 0 h 200 v 150 z');
}
#box1 {
background-color: red;
offset-distance: -280%;
}
#box2 {
background-color: green;
offset-distance: 190%;
}
</style>
<body>
<div class="item" id="box1"></div>
<div class="item" id="box2"></div>
</body>
</code></pre>
<figure>
<img src="images/offset-distance-closed.svg" width="700" height="270"
alt="An example of boxes placed along a closed interval">
<figcaption>An example of boxes placed along a closed interval</figcaption>
</figure>
</div>
<div class=example>
This example shows a way to align boxes within the polar coordinate system using 'offset-path', 'offset-distance'.
<pre><code highlight=html>
<style>
body {
transform-style: preserve-3d;
width: 300px;
height: 300px;
border: dashed gray;
border-radius: 50%;
}
.circleBox {
position: absolute;
left: 50%;
top: 50%;
width: 40px;
height: 40px;
background-color: red;
border-radius: 50%;
}
#circle1 {
offset-path: ray(0deg farthest-side);
offset-distance: 50%;
}
#circle2 {
offset-path: ray(90deg farthest-side);
offset-distance: 20%;
}
#circle3 {
offset-path: ray(225deg farthest-side);
offset-distance: 100%;
}
</style>
<body>
<div class="circleBox" id="circle1"></div>
<div class="circleBox" id="circle2"></div>
<div class="circleBox" id="circle3"></div>
</body>
</code></pre>
<figure>
<img alt="An image of three boxes positioned to polar coordinates" src="images/simple_offset_position.png" width="300" height="300">
<figcaption>An example of positioning box in polar coordinates</figcaption>
</figure>
</div>
<!--
████████ ███████ ██████ ████ ████████ ████ ███████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
███████ ████████ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███
██ ███████ ██████ ████ ██ ████ ███████ ██ ██
-->
Starting Point Of The Path: the 'offset-position' property {#offset-position-property}
-------------------------------------------------------------------------------------------------
<pre class=propdef>
Name: offset-position
Value: normal | auto | <<position>>
Initial: normal
Media: visual
Inherited: no
Applies to: [=transformable elements=]
Percentages: Refer to the size of containing block
Computed value: The ''offset-position/normal'' or ''offset-position/auto'' keywords, or a computed <<position>>
Animation type: by computed value
</pre>
Specifies the <dfn export>offset starting position</dfn>
that is used by the <<offset-path>> functions
if they don't specify their own starting position.
Values are defined as follows:
<dl dfn-for="offset-position" dfn-type="value">
: <dfn>normal</dfn>
::
The element does not have an [=offset starting position=].
: <dfn>auto</dfn>
::
The [=offset starting position=] is the top-left corner of the box.
Note: This is the top-left corner of the element's <em>own box</em>,
not that of its [=containing block=]!
It's completely different from specifiying ''top left''.
It's meant, for example,
to allow a ''path()'' to start relative
to the element's own position.
: <dfn><<position>></dfn>
::
The [=offset starting position=] is the result of using the <<position>>
to position a 0x0 object area
within the box's [=containing block=].
</dl>
<wpt>
parsing/offset-position-computed.html
parsing/offset-position-parsing-invalid.html
parsing/offset-position-parsing-valid.html
</wpt>
<div class=example>
This example shows positioning a box with 'offset-position'.
<pre><code highlight=html>
<style>
#wrap {
position: relative;
width: 300px;
height: 300px;
border: 1px solid black;
}
#box {
width: 100px;
height: 100px;
background-color: green;
position: absolute;
top: 100px;