スタイルobjectPositionプロパティ
例
コンテンツボックスに合わせて画像のサイズを変更し、コンテンツボックス内で画像を左から5ピクセル、上から10%の位置に配置します。
document.getElementById("myImg").style.objectPosition = "0 10%";
定義と使用法
objectPositionプロパティは、<img>または<video>を独自のコンテンツボックスに配置する方法を指定するために使用されます。
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
objectPosition | 31.0 | 16.0 | 36.0 | 10.1 | 19.0 |
構文
objectPositionプロパティを返します。
object.style.objectPosition
objectPositionプロパティを設定します。
object.style.objectPosition = "position|initial|inherit"
プロパティ値
Value | Description |
---|---|
position | Specifies the position of the image or video inside its content box. First value controls the x-asis and the second value controls the y-axis. Can be a string (left, center or right), or a number (in px or %). Negative values are allowed |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | 50%50% |
---|---|
戻り値: | コンテンツボックス内の要素の位置を表す文字列または数値 |
CSSバージョン | CSS3 |
関連ページ
CSSチュートリアル:CSSオブジェクトフィット
CSSリファレンス:object-positionプロパティ
❮スタイルオブジェクト