This example shows how an element's anchor point gets positioned initially at a ray's starting point and how the element gets oriented at the specified ray angle.
CSS
.box1 {
offset-path: ray(0deg closest-side);
}
.box2 {
offset-anchor: 0 0;
offset-path: ray(0deg closest-side);
}
.box3 {
offset-anchor: 0 0;
offset-path: ray(150deg closest-side);
}
.box4 {
offset-anchor: 0 0;
offset-rotate: 0deg;
offset-path: ray(150deg closest-side);
}
Similar to transform-origin
, the default anchor point is at the center of an element. This anchor point can be modified using the offset-anchor
property. The default offset starting position of a path at is the top-left corner of the element box.
In this example, various offset-anchor
and offset-path: ray()
values are applied to a box and results are displayed side-by-side for comparison. One box border is highlighted to demonstrate different ray starting points and box orientations. After a box is positioned at the ray's starting point, it is oriented in the direction of the specified ray angle.
Result
-
box1
gets initially positioned such that its anchor point (at the center) is at the offset starting position (top-left corner). box1
is also rotated to orient it towards the 0deg
angle of the ray. This will now be the starting point of the path. You can observe the change in position and rotation of the box by comparing it to the faded original
box in the background. - The anchor point of
box2
is changed to the top-left corner (0px 0px
) using the anchor-position
property, and as a result, the element's anchor point and the offset starting position coincide. The ray angle is applied to the element at this starting point, the top-left corner. The box is rotated to match the 0deg
angle along y-axis and pointing up. - With other settings the same as in
box2
, a greater positive angle of 150deg
is applied on box3
. Starting from the top-left corner, the box is rotated in a clockwise direction to reach the specified angle. -
box3
and box4
have the same offset-path
and offset-anchor
values. In box4
, a fixed rotation of offset-rotate: 0deg
is applied to the element. As a result, the element will remain rotated at this specific angle all along the ray's path and prevents the element from rotating in the direction of the path. Notice in box4
that the ray path is at 150deg
, but the box orientation will not change along the path.