CSSオブジェクトフィットプロパティ
例
アスペクト比を維持しながら画像の側面を切り取り、スペースを埋めます。
img.a {
width: 200px;
height:
400px;
object-fit: cover;
}
定義と使用法
このobject-fit
プロパティは、コンテナに合わせて<img>または<video>のサイズを変更する方法を指定するために使用されます。
このプロパティは、さまざまな方法でコンテナを埋めるようにコンテンツに指示します。「そのアスペクト比を維持する」や「ストレッチしてできるだけ多くのスペースを占有する」など。
デフォルト値: | 個々のプロパティを参照してください |
---|---|
遺伝性の: | いいえ |
アニメート可能: | 番号。アニメート可能について読む |
バージョン: | CSS3 |
JavaScript構文: | object .style.objectFit = "cover" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
CSS構文
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
プロパティ値
Value | Description | Try it |
---|---|---|
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チュートリアル:CSSオブジェクトフィット
CSSリファレンス:CSSオブジェクトの位置
HTML DOMリファレンス:objectFitプロパティ