HTMLElement: offsetParent プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTMLElement.offsetParent は読み取り専用プロパティで、最も近くにある(包含階層で最も近い)位置指定祖先要素である要素への参照を返します。

位置指定祖先とは、以下のいずれかです。

  • 絶対位置指定要素の場合は包含ブロック
  • この要素とは異なる実効ズーム値(つまり、その親のすべての変倍率の積)を持つ要素。
  • 要素自体が静的位置指定である場合の tdthtable

位置指定祖先要素がない場合は、body を返します。

メモ: 次の状況では、offsetParentnull を返します。

  • 要素またはその祖先要素の display プロパティが none に設定されている。
  • 要素の position プロパティが fixed(固定位置指定)に設定されている(Firefox は <body> を返します)。
  • 要素が <body> または <html> 要素である。

offsetParent が有用なのは、offsetTopoffsetLeft がパディング辺からの相対位置だからです。

現在の要素がオフセットされている要素へのオブジェクト参照です。

仕様書

Specification
CSSOM View Module
# dom-htmlelement-offsetparent

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
offsetParent

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support