スタイルobjectFitプロパティ
例
アスペクト比を維持しながら画像の側面を切り取り、スペースを埋めます。
document.getElementById("myImg").style.objectFit = "cover";
定義と使用法
objectFitプロパティは、コンテナに合わせて<img>または<video>のサイズを変更する方法を指定するために使用されます。
このプロパティは、さまざまな方法でコンテナを埋めるようにコンテンツに指示します。「そのアスペクト比を維持する」または「ストレッチしてできるだけ多くのスペースを占有する」など
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
objectFit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
構文
objectFitプロパティを返します。
object.style.objectFit
objectFitプロパティを設定します。
object.style.objectFit = "fill|contain|cover|scale-down|none|initial|inherit"
プロパティ値
Value | Description |
---|---|
fill | This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit |
contain | The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box |
cover | The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit |
none | The replaced content is not resized |
scale-down | The content is sized as if none or contain were specified (would result in a smaller concrete object size) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | 塗りつぶし |
---|---|
戻り値: | 要素のオブジェクトフィットを表す文字列 |
CSSバージョン | CSS3 |
関連ページ
CSSチュートリアル:CSSオブジェクトフィット
CSSリファレンス:object-fitプロパティ
❮スタイルオブジェクト