CSS offset-position 屬性

定義和用法

offset-position 屬性指定元素在路徑上的初始位置。

如果 offset-path 函數未指定其自身的起始位置,則 offset-position 的值決定了元素在沿偏移路徑移動時的初始位置。

實例

例子 1

指定元素的初始位置應為右下角:

#square {
  width: 60px;
  height: 60px;
  background: blue;
  offset-position: bottom right;
  offset-path: ray(45deg);
}

親自試一試

例子 2

查看不同的偏移起始位置:

#square1 {
  width: 40px;
  height: 40px;
  background: pink;
  text-align:center;
  offset-position: bottom right;
  offset-path: ray(45deg);
}
#square2 {
  width: 40px;
  height: 40px;
  background: red;
  text-align:center;
  offset-position: top right;
  offset-path: ray(25deg);
}
#square3 {
  width: 40px;
  height: 40px;
  background: yellow;
  text-align:center;
  offset-position: normal;
  offset-path: ray(45deg);
}
#square4 {
  width: 40px;
  height: 40px;
  background: cyan;
  text-align:center;
  offset-position: auto;
  offset-path: ray(95deg);
}
#square5 {
  width: 40px;
  height: 40px;
  background: lavender;
  text-align:center;
  offset-position: 30% 70%;
  offset-path: ray(120deg);
}

親自試一試

CSS 語法

offset-position: auto|normal|position|initial|inherit;

屬性值

描述
normal 將偏移起始位置設置為包含塊的 50% 50%。默認值。
auto 將偏移起始位置設置為元素框的左上角。
position

指定一個 x/y 坐標,將元素相對于其框邊緣放置。

可以使用 1 到 4 個值來定義位置。

initial 將此屬性設置為其默認值。參閱 initial
inherit 從其父元素繼承此屬性。參閱 inherit

技術細節

默認值: normal
繼承性:
動畫制作: 支持。請參閱:動畫相關屬性
版本: CSS3
JavaScript 語法: object.style.offsetPosition="auto"

瀏覽器支持

表格中的數字表示首個完全支持該屬性的瀏覽器版本。

Chrome Edge Firefox Safari Opera
116 116 122 16 102

相關頁面

教程:SVG 路徑

教程:CSS 動畫

參考:CSS offset 屬性

參考:CSS offset-anchor 屬性

參考:CSS offset-distance 屬性

參考:CSS offset-path 屬性

參考:CSS offset-rotate 屬性