-
Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
253 lines (201 loc) · 6.46 KB
/
index.md
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
---
title: offset-position
slug: Web/CSS/offset-position
page-type: css-property
browser-compat: css.properties.offset-position
---
{{CSSRef}}
The **`offset-position`** [CSS](/en-US/docs/Web/CSS) property defines the initial position of an element along a path. This property is typically used in combination with the {{cssxref("offset-path")}} property to create a motion effect. The value of `offset-position` determines where the element gets placed initially for moving along an offset path if an `offset-path` function such as {{cssxref("basic-shape/path", "path()")}} does not specify its own starting position.
The `offset-position` property is part of a motion system based on {{cssxref("offset")}} constituent properties, including {{cssxref("offset-anchor")}}, {{cssxref("offset-distance")}}, and `offset-path`. These properties work together to create various motion effects along a path.
## Syntax
```css
/* Keyword values */
offset-position: normal;
offset-position: auto;
offset-position: top;
offset-position: bottom;
offset-position: left;
offset-position: right;
offset-position: center;
/* <percentage> values */
offset-position: 25% 75%;
/* <length> values */
offset-position: 0 0;
offset-position: 1cm 2cm;
offset-position: 10ch 8em;
/* Edge offsets values */
offset-position: bottom 10px right 20px;
offset-position: right 3em bottom 10px;
offset-position: bottom 10px right;
offset-position: top right 10px;
/* Global values */
offset-position: inherit;
offset-position: initial;
offset-position: revert;
offset-position: revert-layer;
offset-position: unset;
```
### Values
- `normal`
- : Indicates that the element does not have an offset starting position and places the element at `50% 50%` of the containing block. This is the default value.
- `auto`
- : Indicates that the offset starting position is the top-left corner of the element's box.
- {{cssxref("<position>")}}
- : Specifies the position as an x/y coordinate to place an element relative to its box edges. The position can be defined using one to four values. If two non-keyword values are used, the first value represents the horizontal position and the second represents the vertical position. If only one value is specified, the second value is assumed to be `center`. If three or four values are used, the {{cssxref("length-percentage")}} values are offsets for the preceding keyword value(s). For more explanation of these value types, see {{cssxref("background-position")}}.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting initial offset-position for an offset-path
In this example, the {{cssxref("offset-path")}} property is used to define the path along which the `cyan` element should move. The value of the {{cssxref("basic-shape/path", "path()")}} CSS function is an [SVG data path](/en-US/docs/Web/SVG/Reference/Attribute/d) that describes a curved path. The element moves along this curved path during the `move` animation.
#### HTML
```html
<div id="wrap">
<div id="motion-demo"></div>
</div>
```
#### CSS
```css hidden
#wrap {
width: 260px;
height: 160px;
border: 1px dashed black;
}
```
```css
#motion-demo {
offset-path: path("M20,20 C20,100 200,0 200,100");
offset-position: left top;
animation: move 3000ms infinite alternate ease-in-out;
width: 40px;
height: 40px;
background: cyan;
}
@keyframes move {
0%,
20% {
offset-distance: 0%;
}
80%,
100% {
offset-distance: 100%;
}
}
```
#### Result
{{EmbedLiveSample('Setting_initial_offset_position_for_an_offset-path', '100%', 200)}}
### Comparing various offset starting positions
This example visually compares various initial offset starting position of an element when {{cssxref("ray", "ray()")}} is used to specify a value for the {{cssxref("offset-path")}} property. The number inside the element box indicates the element to which CSS is applied as well as the element's anchor point.
```html hidden
<div class="wrap">
<div class="box">0</div>
<div class="box box0">0</div>
<pre>
offset-position: normal;
/* No offset-path specified */
</pre>
</div>
<div class="wrap">
<div class="box">0</div>
<div class="box box1">1</div>
<pre>
offset-position: normal;
offset-path: ray(0deg);
</pre>
</div>
<div class="wrap">
<div class="box">0</div>
<div class="box box2">2</div>
<pre>
offset-position: auto;
offset-path: ray(0deg);
</pre>
</div>
<div class="wrap">
<div class="box">0</div>
<div class="box box3">3</div>
<pre>
offset-position: left top;
offset-path: ray(0deg);
</pre>
</div>
<div class="wrap">
<div class="box">0</div>
<div class="box box4">4</div>
<pre>
offset-position: 30% 70%;
offset-path: ray(120deg);
</pre>
</div>
```
```css hidden
.wrap {
position: relative;
width: 80vw;
height: 120px;
border: 1px solid black;
margin: 0 2em 4em 5em;
text-align: center;
}
pre {
font-size: 1em;
text-align: right;
padding-right: 10px;
line-height: 1em;
}
.box {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
}
.box + .box {
opacity: 1;
}
```
```css
.box {
background-color: green;
border-top: 6px dashed white;
background-clip: border-box;
position: absolute;
top: 20px;
left: 20px;
opacity: 20%;
color: white;
}
.box0 {
offset-position: normal;
}
.box1 {
offset-position: normal;
offset-path: ray(0deg);
}
.box2 {
offset-position: auto;
offset-path: ray(0deg);
}
.box3 {
offset-position: left top;
offset-path: ray(0deg);
}
.box4 {
offset-position: 30% 70%;
offset-path: ray(120deg);
}
```
#### Result
{{EmbedLiveSample('Comparing various offset starting positions', '100%', 930)}}
In `box0`, the absence of the `offset-path` property means that an `offset-position` of either `normal` or `auto` has no effect. When `offset-position` is `normal`, the ray starts at the center of the containing block (i.e., `50% 50%`). This is the default starting position of an offset path and is used when no `offset-position` is specified. Notice the difference between offset starting positions `auto` and `left top`. The value `auto` aligns the element's anchor point to its own top-left corner, whereas the value `left top` aligns the element's anchor point to the top-left corner of the containing block.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("offset")}}
- {{cssxref("offset-anchor")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-path")}}
- {{cssxref("offset-rotate")}}